diff options
author | zachir <zachir@librem.one> | 2023-02-24 10:27:34 -0600 |
---|---|---|
committer | zachir <zachir@librem.one> | 2023-02-24 10:27:34 -0600 |
commit | 25af7059733a3f5fe0272d5fdb90f7e2faf54f2d (patch) | |
tree | 8b3eae9a166d93ff4eed47655a6917f0c664fd80 | |
parent | cb1ba09b2a36767afea74460947963542a04be53 (diff) |
add -w and -x flags for dmenu scripts (tofi vs dmenu)
-rwxr-xr-x | dmenu_books | 13 | ||||
-rwxr-xr-x | dmenumount | 23 | ||||
-rwxr-xr-x | dmenuumount | 17 | ||||
-rwxr-xr-x | dmenuunicode | 15 |
4 files changed, 56 insertions, 12 deletions
diff --git a/dmenu_books b/dmenu_books index 367ee37..beb87cc 100755 --- a/dmenu_books +++ b/dmenu_books @@ -1,6 +1,17 @@ #!/bin/sh -BOOK=`ls ~/Documents/shared | dmenu` +printhelp () { + exit +} + +while getopts "hwxd:" o; do case "${o}" in + w) DMENU="tofi" ;; + x) DMENU="dmenu" ;; + d) ARGS="$ARGS$OPTARG " ;; + *) printhelp ;; +esac done + +BOOK=`ls ~/Documents/shared | $DMENU $ARGS` [ -z "$BOOK" ] && exit 1 @@ -5,19 +5,30 @@ # be prompted to give a mountpoint from already existsing directories. If you # input a novel directory, it will prompt you to create that directory. +printhelp () { + exit +} + +while getopts "wxhd:" o; do case "${o}" in + w) DMENU="tofi" ;; + x) DMENU="dmenu" ;; + d) ARGS="$ARGS$OPTARG " ;; + *) printhelp ;; +esac done + getmount() { \ [ -z "$chosen" ] && exit 1 # shellcheck disable=SC2086 - mp="$(find $1 2>/dev/null | dmenu -p "Type in mount point.")" || exit 1 + mp="$(find $1 2>/dev/null | $DMENU $ARGS -p "Type in mount point.")" || exit 1 test -z "$mp" && exit 1 if [ ! -d "$mp" ]; then - mkdiryn=$(printf "No\\nYes" | dmenu -p "$mp does not exist. Create it?") || exit 1 + mkdiryn=$(printf "No\\nYes" | $DMENU $ARGS -p "$mp does not exist. Create it?") || exit 1 [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || doas mkdir -p "$mp") fi } mountusb() { \ - chosen="$(echo "$usbdrives" | dmenu -p "Mount which drive?")" || exit 1 + chosen="$(echo "$usbdrives" | $DMENU $ARGS -p "Mount which drive?")" || exit 1 chosen="$(echo "$chosen" | awk '{print $1}')" echo "$chosen" doas mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 @@ -33,17 +44,17 @@ mountusb() { \ } mountandroid() { \ - chosen="$(echo "$anddrives" | dmenu -p "Which Android device?")" || exit 1 + chosen="$(echo "$anddrives" | $DMENU $ARGS -p "Which Android device?")" || exit 1 chosen="$(echo "$chosen" | cut -d : -f 1)" getmount "$HOME -maxdepth 3 -type d" simple-mtpfs --device "$chosen" "$mp" - echo "OK" | dmenu -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 + echo "OK" | $DMENU $ARGS -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 simple-mtpfs --device "$chosen" "$mp" notify-send "🤖 Android Mounting" "Android device mounted to $mp." } asktype() { \ - choice="$(printf "USB\\nAndroid" | dmenu -p "Mount a USB drive or Android device?")" || exit 1 + choice="$(printf "USB\\nAndroid" | $DMENU $ARGS -p "Mount a USB drive or Android device?")" || exit 1 case $choice in USB) mountusb ;; Android) mountandroid ;; diff --git a/dmenuumount b/dmenuumount index 0584cb4..836bded 100755 --- a/dmenuumount +++ b/dmenuumount @@ -4,22 +4,33 @@ # Provides you with mounted partitions, select one to unmount. # Drives mounted at /, /boot and /home will not be options to unmount. +printhelp () { + exit +} + +while getopts "hwxd:" o; do case "${o}" in + w) DMENU="tofi" ;; + x) DMENU="dmenu" ;; + d) ARGS="$ARGS$OPTARG " ;; + *) printhelp ;; +esac done + unmountusb() { [ -z "$drives" ] && exit - chosen="$(echo "$drives" | dmenu -p "Unmount which drive?")" || exit 1 + chosen="$(echo "$drives" | $DMENU $ARGS -p "Unmount which drive?")" || exit 1 chosen="$(echo "$chosen" | awk '{print $1}')" [ -z "$chosen" ] && exit doas umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." } unmountandroid() { \ - chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -p "Unmount which device?")" || exit 1 + chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | $DMENU $ARGS -p "Unmount which device?")" || exit 1 [ -z "$chosen" ] && exit doas umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted." } asktype() { \ - choice="$(printf "USB\\nAndroid" | dmenu -p "Unmount a USB drive or Android device?")" || exit 1 + choice="$(printf "USB\\nAndroid" | $DMENU $ARGS -p "Unmount a USB drive or Android device?")" || exit 1 case "$choice" in USB) unmountusb ;; Android) unmountandroid ;; diff --git a/dmenuunicode b/dmenuunicode index 704c809..d994614 100755 --- a/dmenuunicode +++ b/dmenuunicode @@ -2,8 +2,19 @@ # The famous "get a menu of emojis to copy" script. -# Get user selection via dmenu from emoji file. -chosen=$(cut -d ';' -f1 ~/.local/share/larbs/chars/* | dmenu -i -l 30 | sed "s/ .*//") +printhelp () { + exit +} + +while getopts "hwxd:" o; do case "${o}" in + w) DMENU="tofi" ;; + x) DMENU="dmenu" ;; + d) ARGS="$ARGS$OPTARG " ;; + *) printhelp ;; +esac done + +# Get user selection via dmenu -i -l 30 from emoji file. +chosen=$(cut -d ';' -f1 ~/.local/share/larbs/chars/* | $DMENU $ARGS | sed "s/ .*//") # Exit if none chosen. [ -z "$chosen" ] && exit |