summaryrefslogtreecommitdiff
path: root/scripts/dmenu-unmount
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dmenu-unmount')
-rwxr-xr-xscripts/dmenu-unmount49
1 files changed, 49 insertions, 0 deletions
diff --git a/scripts/dmenu-unmount b/scripts/dmenu-unmount
new file mode 100755
index 0000000..93c8186
--- /dev/null
+++ b/scripts/dmenu-unmount
@@ -0,0 +1,49 @@
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
9menu=dmenu
10writeout=${NOTIFY:-"notify push"}
11
12usage() {
13 echo "Usage: dmenu-unmount [-m MENU] [-w WRITER]"
14 echo "Example: dmenu-unmount -m slmenu -w echo"
15}
16
17while 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
30done
31shift $((OPTIND - 1))
32
33listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \
34 awk '{print $1" ("$2")"}')
35
36if [ -z "$listdev" ]; then
37 $writeout "Nothing to unmount"
38else
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
49fi

Generated with cgit - Back to sebastiano.tronto.net