diff options
Diffstat (limited to 'dmenumount')
-rwxr-xr-x | dmenumount | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -8,27 +8,34 @@ # input a novel directory, it will prompt you to create that directory. printhelp () { + printf "dmenumount: dmenu prompt to mount drives or android phones\n" + printf "dmenumount [-d X]\n" + printf "\t-d X) pass X as an arg to dmenu\n" exit } while getopts "hd:" o; do case "${o}" in - d) ARGS="$ARGS$OPTARG " ;; + d) ARG=${ARG:+"$ARG "}"$OPTARG" ;; *) printhelp ;; esac done +dmenu_lp () { + dmenu -l 15 -p "$@" +} + getmount() { \ [ -z "$chosen" ] && exit 1 # shellcheck disable=SC2086 - mp="$(find $1 2>/dev/null | dmenu -l 15 -p "Type in mount point." $ARGS)" || exit 1 + mp="$(find $1 2>/dev/null | dmenu_lp "Type in mount point." ${ARG:+"$ARG"})" || exit 1 test -z "$mp" && exit 1 if [ ! -d "$mp" ]; then - mkdiryn=$(printf "No\\nYes" | dmenu -l 15 -p "$mp does not exist. Create it?" $ARGS) || exit 1 + mkdiryn=$(printf "No\\nYes" | dmenu_lp "$mp does not exist. Create it?" ${ARG:+"$ARG"}) || exit 1 [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo mkdir -p "$mp") fi } mountusb() { \ - chosen="$(echo "$usbdrives" | dmenu -l 15 -p "Mount which drive?" $ARGS)" || exit 1 + chosen="$(echo "$usbdrives" | dmenu_lp "Mount which drive?" ${ARG:+"$ARG"})" || exit 1 chosen="$(echo "$chosen" | awk '{print $1}')" echo "$chosen" sudo mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 @@ -44,17 +51,17 @@ mountusb() { \ } mountandroid() { \ - chosen="$(echo "$anddrives" | dmenu -l 15 -p "Which Android device?" $ARGS)" || exit 1 + chosen="$(echo "$anddrives" | dmenu_lp "Which Android device?" ${ARG:+"$ARG"})" || exit 1 chosen="$(echo "$chosen" | cut -d : -f 1)" getmount "$HOME -maxdepth 3 -type d" simple-mtpfs --device "$chosen" "$mp" - echo "OK" | dmenu -l 15 -p "Tap Allow on your phone if it asks for permission and then press enter" $ARGS || exit 1 + echo "OK" | dmenu_lp "Tap Allow on your phone if it asks for permission and then press enter" ${ARG:+"$ARG"} || exit 1 simple-mtpfs --device "$chosen" "$mp" notify-send "🤖 Android Mounting" "Android device mounted to $mp." } asktype() { \ - choice="$(printf "USB\\nAndroid" | dmenu -l 15 -p "Mount a USB drive or Android device?" $ARGS)" || exit 1 + choice="$(printf "USB\\nAndroid" | dmenu_lp "Mount a USB drive or Android device?" ${ARG:+"$ARG"})" || exit 1 case $choice in USB) mountusb ;; Android) mountandroid ;; @@ -66,7 +73,7 @@ alldrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom\|crypt' | for i in $alldrives; do echo "$i" | grep -qi '([0-9.]*[mgt])' && continue - if ! `blkid $i | grep -q 'crypto_LUKS'`; then + if ! blkid "$i" | grep -q 'crypto_LUKS'; then usbdrives="$(echo "$alldrives" | grep "$i")\n$usbdrives" fi done |