dmenuumount.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. unmountusb() {
  6. [ -z "$drives" ] && exit
  7. chosen=$(echo "$drives" | dmenu -i -p "Unmount which drive?" | awk '{print $1}')
  8. [ -z "$chosen" ] && exit
  9. sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted."
  10. }
  11. unmountandroid() { \
  12. chosen=$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")
  13. [ -z "$chosen" ] && exit
  14. sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted."
  15. }
  16. asktype() { \
  17. case "$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" in
  18. USB) unmountusb ;;
  19. Android) unmountandroid ;;
  20. esac
  21. }
  22. drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$2=="part"&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}')
  23. if ! grep simple-mtpfs /etc/mtab; then
  24. [ -z "$drives" ] && echo "No drives to unmount." && exit
  25. echo "Unmountable USB drive detected."
  26. unmountusb
  27. else
  28. if [ -z "$drives" ]
  29. then
  30. echo "Unmountable Android device detected."
  31. unmountandroid
  32. else
  33. echo "Unmountable USB drive(s) and Android device(s) detected."
  34. asktype
  35. fi
  36. fi