commit 115ff9a06870d51702918cd926199e2271bf4f92
parent 5ca3ebbf7c3cef6db6b8270af4fcf0be087c29c1
Author: Sebastiano Tronto <sebastiano.tronto@gmail.com>
Date: Sun, 15 May 2022 12:02:59 +0200
Added option to specify alternative menu. Some general cleanup.
Diffstat:
12 files changed, 105 insertions(+), 44 deletions(-)
diff --git a/Makefile b/Makefile
@@ -41,7 +41,6 @@ SCRIPTS = addressgrep \
websearch \
xedit \
xedit-filter \
- xkboptions \
xplumb \
xprop-active-window-id \
xwallpaper-random-notify
diff --git a/TODO b/TODO
@@ -1,11 +1,6 @@
-* Modify all dmenu-* scripts to optionally use another menu, like vis-menu (slmenu)
- Do this by taking an optional $1 which is the name of the program to use
- (optional $dir argument is removed: fix dmenu-bookmarks simply using cd)
-* Big problem: slmenu does not allow multiple selections; this is a problem
- for my workflow for sel and for sfeed-menu (and sometimes for open-file)
-* Solution: leave dmenu default option, use slmenu for a selected few aliases in .profile
-
-* mblaze-extras: remove mmv, just use complete_mrefile=mail/...
+* dmenu-bookmarks: add option for different directory
+
+* mblaze-extras: maybe remove script and just use aliases?
* sfeed-browser: optionally just write link to stdout (or to xsel -i)
diff --git a/clip b/clip
@@ -7,12 +7,20 @@
# Bugs (wontfix): the program fails if it can't create the temporary
# directory with the designated name.
-# Requires: xsel, dmenu
+# Usage: clip [-m menu]
-# TODO: improve formatting in dmenu
+# Requires: xsel, dmenu (or similar)
-menu="dmenu"
-menuopts="-l 25"
+menu="dmenu -i -l 25"
+
+while getopts "m:" opt; do
+ case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
dir="/tmp/clipdir"
mkdir -p "$dir"
@@ -38,7 +46,7 @@ for f in $dir/*; do
printf "$fclean ($nlines) | $(head -n 1 $f)\n" >> "$lines"
done
-selected=$(sort -r $lines | $menu $menuopts | awk '{print $1}')
+selected=$(sort -r $lines | $menu | awk '{print $1}')
if [ -n "$selected" ]; then
xsel -ib < "$dir/$selected"
fi
diff --git a/dmenu-bookmarks b/dmenu-bookmarks
@@ -2,10 +2,13 @@
# A bookmark browser based on dmenu
-# Requires: dmenu-filepicker, open-url
+# Usage: dmenu-bookmarks [picker options...]
+
+# Requires: dmenu-filepicker (or similar), open-url
dir=$HOME/box/bookmarks
+picker="dmenu-filepicker"
-echo "$(dmenu-filepicker $dir)" | while read line; do
+echo "$($picker "$@" $dir)" | while read line; do
cat "$line"
done | xargs open-url
diff --git a/dmenu-dwm-sessionmanager b/dmenu-dwm-sessionmanager
@@ -1,18 +1,26 @@
#!/bin/sh
# Prompts menu to shutdown/reboot/close dwm
+# Usage: dmenu-dwm-sessionmanager [-m menu]
# Requires: dmenu (or equivalent), dwm (optional)
-menu=${MENU:-dmenu}
-menuopts="-i -p"
-menuprompt="Do you want to quit?"
-wmname="dwm"
+menu="dmenu -i"
+prompt="Do you want to quit?"
+while getopts "m:" opt; do
+ case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
+wmname="dwm"
shutdown_cmd="sudo shutdown -h now"
reboot_cmd="sudo reboot"
closewm_cmd="pkill $wmname"
-value=$(echo "Shutdown\nReboot\nQuit dwm" | $menu $menuopts "$menuprompt")
+value=$(echo "Shutdown\nReboot\nQuit dwm" | $menu -p "$prompt")
if [ "$value" = "Shutdown" ]; then
$shutdown_cmd
diff --git a/dmenu-filepicker b/dmenu-filepicker
@@ -2,10 +2,18 @@
# A dmenu-based file picker (prints selected file to stdout)
# Requires: dmenu (or similar)
-# Usage: dmenu-filepicker [path]
+# Usage: dmenu-filepicker [-m menu] [path]
-menu=dmenu
-menuopts="-i -l 15"
+menu="dmenu -i -l 15"
+
+while getopts "m:" opt; do
+ case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
fullpath=$(realpath ${@:-"$(pwd)"})
@@ -15,7 +23,7 @@ while true; do
break
elif [ -d "$fullpath" ] || [ -z "$fullpath" ]; then
if [ -z "$fullpath" ]; then fp="/"; else fp="$fullpath"; fi
- sel=$(ls -a "$fp" | sed 's|.*/||' | $menu $menuopts)
+ sel=$(ls -a "$fp" | sed 's|.*/||' | $menu)
if [ "$sel" = ".." ]; then
fullpath=$(echo "$fullpath" | sed "s|/[^/]*$||")
else
diff --git a/dmenu-mail-aliases b/dmenu-mail-aliases
@@ -2,10 +2,19 @@
# Select mail alias via dmenu
# The email address must be the second word in a line of $aliasfile
+# Usage: dmenu-mail-aliases [-m menu]
# Requires: dmenu (or similar)
-menu=${MENU:-dmenu}
-menuopts="-l 20"
+menu="dmenu -l 20"
aliasfile="$HOME/.mblaze/aliases"
+while getopts "m:" opt; do
+ case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
+
$menu $menuopts <"$aliasfile" | awk '{print $NF}'
diff --git a/dmenu-screenshot b/dmenu-screenshot
@@ -1,17 +1,26 @@
#!/bin/sh
# Screenshot utility
+# Usage: dmenu-screenshot [-m menu]
# Requires: dmenu (or similar), imagemagick
-menu=${MENU:-dmenu}
-menuopts="-i -p"
-menuprompt="Select type of screenshot:"
+menu="dmenu -i"
+prompt="Select type of screenshot:"
+
+while getopts "m:" opt; do
+ case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
folder="$HOME/Pictures/screenshots"
filename="screenshot_$(date +%Y-%m-%d-%H%M%S).png"
filepath="${folder}/${filename}"
-t=$(echo "Full\nSelection" | $menu $menuopts "$menuprompt")
+t=$(echo "Full\nSelection" | $menu -p "$prompt")
#op="" TODO: remove if not needed
if [ "$t" = "Full" ]; then
op="-window root"
diff --git a/dmenu-unmount b/dmenu-unmount
@@ -1,10 +1,24 @@
#!/bin/sh
# Prompts selection for mounted devices and unmounts the selected one
+# 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=${MENU:-dmenu}
-writeout=herbe # Change this to whatever you want, e.g. echo or notify-send
+menu=dmenu
+writeout=herbe
+
+while getopts "m:w:" opt; do
+ case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
+ w)
+ writeout="$OPTARG"
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
listdev=$(grep "media" /proc/mounts | sed 's/\/media.*\///g' | \
awk '{print $1" ("$2")"}')
diff --git a/dmenu-urlselect b/dmenu-urlselect
@@ -2,9 +2,18 @@
# Finds all URLs in stdin and prompts a dmenu choice, then writes the selected
# url to stdout.
+# Usage: dmenu-urlselect [-m menu]
# Requires: dmenu (or similar), urlgrep
-menu=${MENU:-dmenu}
-menuopts="-l 20"
+menu="dmenu -i -l 20"
-urlgrep | $menu $menuopts
+while getopts "m:" opt; do
+ case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
+ esac
+done
+shift `expr $OPTIND - 1`
+
+urlgrep | $menu
diff --git a/xkboptions b/old/xkboptions
diff --git a/open-file b/open-file
@@ -2,9 +2,10 @@
# Inspired by https://github.com/salman-abedin/launch.sh
# Launches files based on their mimetypes
+# Usage: open-file [-m menu] [-s launcher] [-t mimetype] [files...]
# Requires: dmenu_path or similar (fallback), dmenu-filepicker
-menu=${MENU:-dmenu}
+menu="dmenu -i -l 15"
# Change default apps here
video="mpv"
@@ -78,8 +79,11 @@ openfile() {
fi
}
-while getopts "s:t:" opt; do
+while getopts "m:s:t:" opt; do
case "$opt" in
+ m)
+ menu="$OPTARG"
+ ;;
s)
launcher="$OPTARG"
;;
@@ -89,11 +93,6 @@ while getopts "s:t:" opt; do
esac
done
-# If launcher = "", assume running in terminal, so some programs change
-#if [ -z "$launcher" ]; then
-# xedit=${EDITOR:-vi}
-#fi
-
shift `expr $OPTIND - 1`
toopen=$@
@@ -103,7 +102,7 @@ if [ -n "$1" ]; then
shift
done
else
- dmenu-filepicker | while read line; do
+ dmenu-filepicker -m "$menu" | while read line; do
openfile "$line" &
done
fi