#!/bin/sh # # DESCRIPTION: # dmenu-based mount/unmount helper # [ -n "$DEBUG" ] && set -x [ "$1" = "-o" ] && open=1 # check requirements for app in awk jq lsblk notify-send udisksctl swx vifm; 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" mount() { line=$1 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}" logfile=$(mktemp --tmpdir -t "mnts-${label}-XXXXX") if udisksctl "${mode}" -b "${drv}" >"${logfile}" 2>&1; then if [ "${mode}" = "mount" ]; then op=plus _op="+" else op=remove _op="-" fi notify-send -i /usr/share/icons/mdi/scalable/harddisk-${op}.svg -a mnts mnts "$(cat "${logfile}")" printf "%s\t%s\t%s\n" "${_op}" "${drv}" "${path}" [ -n "${open}" ] && [ "${mode}" = "mount" ] && swx -t -- vifm "${path}" else notify-send -i /usr/share/icons/mdi/scalable/harddisk.svg -a mnts -u critical -t 30000 mnts "${mode}ing ${label} failed:\n$(cat "${logfile}")" fi rm "${logfile}" } handle() { while read -r line; do mount "${line}" & done } 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 --list=8 \ | handle