| 1 | #!/bin/sh |
| 2 | |
| 3 | # A dmenu prompt to unmount drives. |
| 4 | # Provides you with mounted partitions, select one to unmount. |
| 5 | # Drives mounted at /, /boot and /home will not be options to unmount. |
| 6 | |
| 7 | unmountusb() { |
| 8 | [ -z "$drives" ] && exit |
| 9 | chosen="$(echo "$drives" | aurora-run -d -p "Unmount which drive?")" || exit 1 |
| 10 | chosen="$(echo "$chosen" | awk '{print $1}')" |
| 11 | [ -z "$chosen" ] && exit |
| 12 | sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." |
| 13 | } |
| 14 | |
| 15 | 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}') |
| 16 | |
| 17 | if [ -z "$drives" ]; then |
| 18 | echo "No drives to unmount." && exit |
| 19 | else |
| 20 | echo "Unmountable USB drive detected." |
| 21 | unmountusb |
| 22 | fi |