#!/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${_outp}" 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