summaryrefslogtreecommitdiff
path: root/dmenumount
blob: dde420b8faded85609f86451cb3d92a0b417ccaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/bin/sh
# Dependency: https://github.com/RHL120/openbsd_lsblk
# Idea: If you want to, change doas.conf to allow lsblk to run without password (lsblk requires privileges).
# USAGE: use "dmenumount m" and "dmenumount u" for mounting and unmounting, respectively.
# Put something like SHCMD("sh -c 'st -e dmenumount m'") as a binding into you WM config (in my case DWM).

if [[ $1 == m ]]; then
	disk=$(echo $(doas lsblk | awk 'BEGIN{OFS=""} {if ($4=="")  print $1, "(", $2, ")"}' | sed -r '/[0-9]\(|\(.*[0-9]b\)/d' | sed -e 's/|-//g' | dmenu) | sed -E 's/\(.*\)//g')
	[[ -z "$disk" ]] && exit || doas mount /dev/$disk /mnt 
elif [[ $1 == u ]]; then
	dir=$(mount | awk 'BEGIN{OFS=""} !/'sd0'/ {print $3,"(",$1,")"}' | dmenu | sed -E 's/\(.*\)//')
	[[ -z "$dir" ]] && exit || doas umount $dir
else
	echo "Not a valid option."
fi