dmenuumount 1.4 KB

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