Another copy of my dotfiles. Because I don't completely trust GitHub.
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.

83 lines
1.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
  1. #!/bin/sh
  2. DMENU=${DMENU:-dmenu}
  3. DEV_LABEL="/dev/disk/by-label/"
  4. TMP="$XDG_RUNTIME_DIR/dmnt-udevil-$(date +%s)"
  5. trap "rm -f $TMP" EXIT
  6. opt_mount_type=0
  7. opt_ignore_filter=1
  8. opt_notify=1
  9. udevil_cmd="mount"
  10. usage() {
  11. cat <<-EOF
  12. usage: dmenu-udevil [-mudihn]
  13. -m Mount devices
  14. -u Unmount devices
  15. -d Select by device rather than by label
  16. -i Ignore filter and list all devices in /dev (with -d)
  17. -n Pass udevil output to notify-send
  18. -h Print help
  19. EOF
  20. }
  21. dmenu_mnt() {
  22. if [[ $opt_mount_type -eq 1 ]]; then
  23. prompt="$udevil_cmd by-device:"
  24. if [[ $opt_ignore_filter -eq 0 ]]; then
  25. res="$(find /dev -maxdepth 1 -not -type d -name "s[dr]*" -or -name "hd*" | cut -d'/' -f3 | ${DMENU} -p "$prompt")"
  26. else
  27. res="$(find /dev -maxdepth 1 -not -type d | cut -d'/' -f3 | ${DMENU} -p "$prompt")"
  28. fi
  29. path="/dev/$res"
  30. [[ -z $res ]] && echo "Cancelled." && exit
  31. else
  32. prompt="$udevil_cmd by-label:"
  33. res="$(find $DEV_LABEL* | cut -d'/' -f5 | ${DMENU} -p "$prompt")"
  34. path="$DEV_LABEL/$res"
  35. [[ -z $res ]] && echo "Cancelled." && exit
  36. fi
  37. if [ "$udevil_cmd" = "mount" ]; then
  38. udevil $udevil_cmd "$path" "/media/$(whoami)/$res"> "$TMP" 2>&1
  39. msg=$(cat $TMP)
  40. else
  41. udevil --verbose $udevil_cmd "$path" > "$TMP" 2>&1
  42. #msg=$(grep "umount: " "$TMP" | cut -c '9-')
  43. msg=""
  44. fi
  45. exitc=$?
  46. if [[ $opt_notify -eq 1 ]]; then
  47. case $exitc in
  48. 0) urgency="normal";;
  49. *) urgency="critical";;
  50. esac
  51. notify-send -u $urgency "$msg"
  52. else
  53. cat $TMP
  54. fi
  55. }
  56. while getopts ':mudhin' opt; do
  57. case "$opt" in
  58. m) ;;
  59. u) udevil_cmd="umount";;
  60. d) opt_mount_type=1;;
  61. i) opt_ignore_filter=1;;
  62. h) usage && exit;;
  63. n) opt_notify=1;;
  64. /?) echo "Unrecognized command: $OPTARG";;
  65. esac
  66. done
  67. dmenu_mnt && exit