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.

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