1
0
Fork 0
dotfiles/.local/bin/dmenuumount

33 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
# A dmenu prompt to unmount drives.
# Provides you with mounted partitions, select one to unmount.
# Drives mounted at /, /boot and /home will not be options to unmount.
drives="$(
lsblk -nrpo "name,type,size,mountpoint,label" | awk -F':' '{gsub(/ /,":")}$4!~/\/boot|\/efi|\/home$|SWAP/&&length($4)>1{printf "%s (%s) %s\n",$4,$3,$5}'
awk '/simple-mtpfs/ { print "", $2; }' /etc/mtab
)"
chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1
if case "$chosen" in
*)
chosen="${chosen#📱 }"
sudo -A umount -l "$chosen"
;;
*)
chosen="${chosen% (*}"
sudo -A umount -l "$chosen"
;;
esac
then
notify-send "禍 Drive unmounted." "$chosen successfully unmounted."
else
notify-send "禍 Drive failed to unmount." "Possibly a permissions or I/O issue."
fi
sudo -A umount "$chosen" && notify-send "禍 USB unmounting" "$chosen unmounted."
sudo -A umount -l "$chosen" && notify-send " Android unmounting" "$chosen unmounted."