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

73 lines
1.7 KiB
Nix
Raw Normal View History

2024-11-04 04:37:29 +03:00
{ ... }: {
text = ''
# Show only physical drives info.
function pdf() {
df --si | sed -e '1p' -e '/^\/dev\//!d'
}
2024-04-06 03:03:58 +03:00
2024-11-04 04:37:29 +03:00
# 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
2024-11-04 04:37:29 +03:00
# Unlock encrypted disk file.
# Usage: funlock <FILE>
function funlock() {
local file="''${1}"
2024-04-15 17:58:37 +03:00
2024-11-04 04:37:29 +03:00
if [[ "''${file}" = "" ]]; then
help funlock
return 2
fi
2024-11-04 04:37:29 +03:00
local name=$(parse_alnum "''${file##*/}")
2024-11-04 04:37:29 +03:00
local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}")
loop="''${loop##* }"; loop="''${loop%.}"
2024-11-04 04:37:29 +03:00
local decrypted=$(udisksctl unlock --block-device "''${loop}")
decrypted="''${decrypted##* }"; decrypted="''${decrypted%.}"
2024-11-04 04:37:29 +03:00
local mount=$(udisksctl mount --no-user-interaction --block-device "''${decrypted}")
mount="''${mount#* at }"
2024-11-04 04:37:29 +03:00
ya pub dds-cd --str "''${mount}" 2> /dev/null
cd "''${mount}"
}
2024-11-04 04:37:29 +03:00
# Mount file.
# Usage: fmount <FILE>
function fmount() {
local file="''${1}"
if [[ "''${file}" = "" ]]; then
help fmount
return 2
fi
2024-11-04 04:37:29 +03:00
local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}")
loop="''${loop##* }"; loop="''${loop%.}"
2024-11-04 04:37:29 +03:00
local mount=$(udisksctl mount --no-user-interaction --block-device "''${loop}")
mount="''${mount#* at }"
2024-11-04 04:37:29 +03:00
ya pub dds-cd --str "''${mount}" 2> /dev/null
cd "''${mount}"
}
2024-11-04 04:37:29 +03:00
# Unmount file.
# Usage: fumount <LOOPDEVICE>
function fumount() {
local loop="''${1}"
if [[ "''${loop}" = "" ]]; then
help fumount
return 2
fi
2024-11-04 04:37:29 +03:00
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
}