From af4f814b0cb8326368d3ccaa9934ec9342f0728a Mon Sep 17 00:00:00 2001 From: mokulus <36231852+mokulus@users.noreply.github.com> Date: Sun, 26 Apr 2020 01:18:06 +0200 Subject: dmenumount fix + improvements (#602) * Remove misleading character escape. Everything is in single quotes, so shell will escape it correctly without backslashes. Fixes #440. * Remove lsblk type restriction. * Make it possible to cancel with ESC in dmenu. Up to now if you pressed ESC to cancel the program would just continue with incorrect data. --- .local/bin/dmenuumount | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to '.local/bin/dmenuumount') diff --git a/.local/bin/dmenuumount b/.local/bin/dmenuumount index da0f401..26612ef 100755 --- a/.local/bin/dmenuumount +++ b/.local/bin/dmenuumount @@ -6,25 +6,27 @@ unmountusb() { [ -z "$drives" ] && exit - chosen=$(echo "$drives" | dmenu -i -p "Unmount which drive?" | awk '{print $1}') + chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1 + chosen="$(echo "$chosen" | awk '{print $1}')" [ -z "$chosen" ] && exit sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." } unmountandroid() { \ - chosen=$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?") + chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1 [ -z "$chosen" ] && exit sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted." } asktype() { \ - case "$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" in + choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1 + case "$choice" in USB) unmountusb ;; Android) unmountandroid ;; esac } -drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$2=="part"&&$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}') +drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}') if ! grep simple-mtpfs /etc/mtab; then [ -z "$drives" ] && echo "No drives to unmount." && exit -- cgit v1.3.1