Dotfiles for different machines on different branches.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
2.3 KiB

  1. #!/bin/sh
  2. # Gives a dmenu prompt to mount unmounted drives.
  3. # If they're in /etc/fstab, they'll be mounted automatically.
  4. # Otherwise, you'll be prompted to give a mountpoint from already existsing directories.
  5. # If you input a novel directory, it will prompt you to create that directory.
  6. # by lukesmithxyz, checkout github.com/lukesmithxyz/voidrice
  7. getmount() { \
  8. [ -z "$chosen" ] && exit 1
  9. mp="$(find $1 2>/dev/null | dmenu -i -p "Type in mount point.")"
  10. [ "$mp" = "" ] && exit 1
  11. if [ ! -d "$mp" ]; then
  12. mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?")
  13. [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp")
  14. fi
  15. }
  16. mountusb() { \
  17. chosen="$(echo "$usbdrives" | dmenu -i -p "Mount which drive?" | awk '{print $1}')"
  18. sudo -A mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0
  19. alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$2=="part"&&$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not \\( -path *%s -prune \\) \\ \n",$3}')
  20. getmount "/mnt /media /mount /home -maxdepth 5 -type d $alreadymounted"
  21. partitiontype="$(lsblk -no "fstype" "$chosen")"
  22. case "$partitiontype" in
  23. "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;;
  24. *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";;
  25. esac
  26. notify-send "💻 USB mounting" "$chosen mounted to $mp."
  27. }
  28. mountandroid() { \
  29. chosen=$(echo "$anddrives" | dmenu -i -p "Which Android device?" | cut -d : -f 1)
  30. getmount "$HOME -maxdepth 3 -type d"
  31. simple-mtpfs --device "$chosen" "$mp"
  32. notify-send "🤖 Android Mounting" "Android device mounted to $mp."
  33. }
  34. asktype() { \
  35. case $(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?") in
  36. USB) mountusb ;;
  37. Android) mountandroid ;;
  38. esac
  39. }
  40. anddrives=$(simple-mtpfs -l 2>/dev/null)
  41. usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | awk '$2=="part"&&$4==""{printf "%s (%s)\n",$1,$3}')"
  42. if [ -z "$usbdrives" ]; then
  43. [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit
  44. echo "Android device(s) detected."
  45. mountandroid
  46. else
  47. if [ -z "$anddrives" ]; then
  48. echo "USB drive(s) detected."
  49. mountusb
  50. else
  51. echo "Mountable USB drive(s) and Android device(s) detected."
  52. asktype
  53. fi
  54. fi