nix/home/program/bash/module/Disk.nix

71 lines
1.6 KiB
Nix
Raw Normal View History

2024-04-06 03:03:58 +03:00
{ ... }: {
text = ''
# Show only physical drives info.
function pdf() {
df --si | sed -e '1p' -e '/^\/dev\//!d'
}
# Show total size in SI.
# Current dir by default.
# Usage: tdu [DIRS]
function tdu() {
du -sh --si "''${@}"
}
2024-04-15 17:58:37 +03:00
# Unlock encrypted disk file.
# Usage: funlock <FILE>
2024-10-04 13:50:06 +03:00
function funlock() {
2024-04-15 17:58:37 +03:00
local file="''${1}"
if [[ "''${file}" = "" ]]; then
2024-10-04 13:50:06 +03:00
help funlock
return 2
fi
local name=$(parse_alnum "''${file##*/}")
local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}")
loop="''${loop##* }"; loop="''${loop%.}"
local decrypted=$(udisksctl unlock --block-device "''${loop}")
decrypted="''${decrypted##* }"; decrypted="''${decrypted%.}"
local mount=$(udisksctl mount --no-user-interaction --block-device "''${decrypted}")
mount="''${mount#* at }"
cd "''${mount}"
2024-04-15 17:58:37 +03:00
}
# Mount file.
# Usage: fmount <FILE>
function fmount() {
local file="''${1}"
if [[ "''${file}" = "" ]]; then
help fmount
return 2
fi
local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}")
loop="''${loop##* }"; loop="''${loop%.}"
local mount=$(udisksctl mount --no-user-interaction --block-device "''${loop}")
mount="''${mount#* at }"
cd "''${mount}"
}
# Unmount file.
# Usage: fumount <LOOPDEVICE>
function fumount() {
local loop="''${1}"
if [[ "''${loop}" = "" ]]; then
help fumount
return 2
fi
udisksctl unmount --no-user-interaction --block-device "''${loop}"
udisksctl loop-delete --no-user-interaction --block-device "''${loop}"
}
2024-04-06 03:03:58 +03:00
'';
}