blob: cb1093cd5a2eb7315760bd1557799246809fec0b (
plain) (
blame)
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
|
#!/bin/sh
#
# DESCRIPTION:
# dmenu-based mount/unmount helper
#
[ -n "$DEBUG" ] && set -x
# check requirements
for app in awk jq lsblk notify-send udisksctl; do
if ! command -v "$app" >/dev/null; then
printf "%s: %s not installed but required\n" "$(basename "$0")" "$app" >&2
exit 1
fi
done
export MENU_PROMPT="mnts"
handle() {
line=$(awk '{print $0}')
[ -z "${line}" ] && exit 0
path=$(echo "${line}"|awk -F\\t '{print $3}'|xargs)
mode=$(echo "${line}"|awk -F\\t '{if(length($3)<1) print "mount";else print "unmount";}'|xargs)
drv=$(echo "${line}"|awk -F\\t '{print $1}'|xargs)
label=$(echo "${line}"|awk -F\\t '{print $2}'|xargs)
[ -n "${DEBUG}" ] && printf 'DEBUG: mode:%s, drv:%s, path:%s\n' "${mode}" "${drv}" "${path}";
_outp=$(udisksctl "${mode}" -b "${drv}" 2>&1)
if [ $? = 0 ]; then \
notify-send -a mnts mnts "${_outp}"
else
notify-send -a mnts -u critical -t 30000 mnts "${mode}ing ${label} failed:\n<i>${_outp}</i>"
fi
}
lsblk -fJ \
| jq -r '.. | select(.uuid?!="" and .name?) | select((.name | test("hibiki|nvme") | not) and .fstype?) | [ .name, .label, .mountpoint // "" ] | @tsv' \
| awk -F'\t' '{printf "/dev/%-10s\t%-15s\t%s\n", $1, $2, $3;}' \
| menu \
| handle
|