dmenu-unmount (1057B)
1 #!/bin/sh 2 3 # Prompts selection for mounted devices and unmounts the selected one 4 # Requires: udevil, dmenu (or similar), notify-send or similar (optional) 5 6 # Usage: dmenu-unmount [-m menu] [-w writer] 7 # Example: dmenu-unmount -m slmenu -w echo 8 9 menu=dmenu 10 writeout=${NOTIFY:-"notify push"} 11 12 usage() { 13 echo "Usage: dmenu-unmount [-m MENU] [-w WRITER]" 14 echo "Example: dmenu-unmount -m slmenu -w echo" 15 } 16 17 while getopts "m:w:" opt; do 18 case "$opt" in 19 m) 20 menu="$OPTARG" 21 ;; 22 w) 23 writeout="$OPTARG" 24 ;; 25 *) 26 usage 27 exit 1 28 ;; 29 esac 30 done 31 shift $((OPTIND - 1)) 32 33 listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \ 34 awk '{print $1" ("$2")"}') 35 36 if [ -z "$listdev" ]; then 37 $writeout "Nothing to unmount" 38 else 39 seldev=$(echo "$listdev" | $menu | awk '{print $1}') 40 if [ -n "$seldev" ]; then 41 udevil unmount "$seldev" 42 failed=$(udevil info "$seldev" | grep mounted | awk '{print $3}') 43 if [ "$failed" -eq 1 ]; then 44 $writeout "Unmount FAILED" "Device is still mounted!" 45 else 46 $writeout "Device unmounted" 47 fi 48 fi 49 fi