dmenuumount (1277B)
1 #!/bin/sh 2 # A dmenu prompt to unmount drives. 3 # Provides you with mounted partitions, select one to unmount. 4 # Drives mounted at /, /boot and /home will not be options to unmount. 5 6 unmountusb() { 7 [ -z "$drives" ] && exit 8 chosen=$(echo "$drives" | dmenu -i -p "Unmount which drive?" | awk '{print $1}') 9 [ -z "$chosen" ] && exit 10 sudo -A umount "$chosen" && pgrep -x dunst && notify-send "$chosen unmounted." 11 } 12 13 unmountandroid() { \ 14 chosen=$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?") 15 [ -z "$chosen" ] && exit 16 fusermount -u "$chosen" && pgrep -x dunst && notify-send "$chosen unmounted." 17 } 18 19 asktype() { \ 20 case $(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?") in 21 USB) unmountusb ;; 22 Android) unmountandroid ;; 23 esac 24 } 25 26 drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$2=="part"&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}') 27 28 if ! grep simple-mtpfs /etc/mtab; then 29 [ -z "$drives" ] && echo "No drives to unmount." && exit 30 echo "Unmountable USB drive detected." 31 unmountusb 32 else 33 if [ -z "$drives" ] 34 then 35 echo "Unmountable Android device detected." 36 unmountandroid 37 else 38 echo "Unmountable USB drive(s) and Android device(s) detected." 39 asktype 40 fi 41 fi