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