From 581865ee0c8b8aea872f053d804a41fb5f416b17 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 20 Jun 2023 23:01:09 +0200 Subject: Various shellcheck fixes (www.shellcheck.net) --- dmenu-unmount | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'dmenu-unmount') diff --git a/dmenu-unmount b/dmenu-unmount index 2771ecc..8f7a27f 100755 --- a/dmenu-unmount +++ b/dmenu-unmount @@ -1,14 +1,20 @@ #!/bin/sh # Prompts selection for mounted devices and unmounts the selected one +# Requires: udevil, dmenu (or similar), notify-send or similar (optional) + # Usage: dmenu-unmount [-m menu] [-w writer] # Example: dmenu-unmount -m slmenu -w echo -# Requires: udevil, dmenu (or similar), notify-send or similar (optional) menu=dmenu #writeout=notify-send writeout="notify push" +usage() { + echo "Usage: dmenu-unmount [-m MENU] [-w WRITER]" + echo "Example: dmenu-unmount -m slmenu -w echo" +} + while getopts "m:w:" opt; do case "$opt" in m) @@ -17,9 +23,13 @@ while getopts "m:w:" opt; do w) writeout="$OPTARG" ;; + *) + usage + exit 1 + ;; esac done -shift `expr $OPTIND - 1` +shift $((OPTIND - 1)) listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \ awk '{print $1" ("$2")"}') @@ -31,11 +41,10 @@ else if [ -n "$seldev" ]; then udevil unmount "$seldev" failed=$(udevil info "$seldev" | grep mounted | awk '{print $3}') - if [ $failed -eq 1 ]; then + if [ "$failed" -eq 1 ]; then $writeout "Unmount FAILED" "Device is still mounted!" else $writeout "Device unmounted" fi fi fi -# notify-send "$(udisksctl unmount -b $seldev)" -- cgit v1.3