summaryrefslogtreecommitdiff
path: root/bin/menuscripts
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2023-08-30 08:23:45 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2023-08-30 08:23:45 +0200
commit3f8594ee04d2a3d9b40a259daf3b564a53b510fa (patch)
tree66ed50643cdc81af813b5771a99732d0f78bb618 /bin/menuscripts
parent45d39ae0c67bb086f4df0c366b251e06c888408d (diff)
parent333aaf38c66a1e4ba41d3acea38b21613c0075b2 (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'bin/menuscripts')
-rwxr-xr-xbin/menuscripts/commander321
-rwxr-xr-xbin/menuscripts/mapimg13
-rwxr-xr-xbin/menuscripts/mcurs25
-rwxr-xr-xbin/menuscripts/mdsktp21
-rwxr-xr-xbin/menuscripts/memoji21
-rwxr-xr-xbin/menuscripts/mhelp39
-rwxr-xr-xbin/menuscripts/mmpcvol20
-rwxr-xr-xbin/menuscripts/mpass38
-rwxr-xr-xbin/menuscripts/mpassgen45
-rwxr-xr-xbin/menuscripts/mpdf24
-rwxr-xr-xbin/menuscripts/mplay20
-rwxr-xr-xbin/menuscripts/mpower18
-rwxr-xr-xbin/menuscripts/mvid29
13 files changed, 413 insertions, 221 deletions
diff --git a/bin/menuscripts/commander b/bin/menuscripts/commander
new file mode 100755
index 0000000..ff58a56
--- /dev/null
+++ b/bin/menuscripts/commander
@@ -0,0 +1,321 @@
+#!/bin/sh
+
+# An attempt to unify usage of multiple launchers.
+# MENUCMD must be set to the name of the lancher
+#
+# look at the last line to understand how it works
+
+tmp="$(mktemp -u)"
+export menuopts=""
+TOFIRC="$HOME/.config/tofi/config"
+
+options='
+horizontal
+center
+input
+instant
+dynamic
+long
+prompt
+numbered
+prefix'
+
+cleanup() { rm -f "$tmp"; }
+
+logn()
+{
+ [ "${log_on:=0}" -eq 0 ] && return
+ >&2 printf '%s\n' "$@"
+}
+
+run() {
+ IFS=:
+ set -f
+ find -L $PATH -type f -printf "%f\n" 2> /dev/null | sort -u
+}
+
+help() {
+ cat <<-EOF
+ Usage: commander OPTIONS...
+
+ An attempt to regroup multiple launchers into one,
+ it detects the value of the MENUCMD variable
+
+ try:
+ MENUCMD=tofi commander < /etc/passwd
+
+ Options:
+ -h Display items horizontally
+ -c Display centered
+ -i Take an input and return it to stdout
+ -d Adjust size and style dynamically
+ -p ARG Prompt user with the specified argument
+ -l Display in long list format
+ -n Output the number of matches
+ -r Select an executable from PATH
+ -s Invert instant select on single match
+ -x Invert prefix matching
+ EOF
+}
+
+add_option() { menuopts="$menuopts $*"; }
+get_prop() { awk -F '=' "/$1 *=*/ {print \$2}" "$TOFIRC"; }
+
+
+trap cleanup EXIT
+
+# Helper functions
+case "$MENUCMD" in
+ "tofi")
+ # $1: items count
+ get_height()
+ {
+ font_size="$(get_prop "font-size")"
+ padding_top="$(get_prop "padding-top")"
+ padding_bottom="$(get_prop "padding-bottom")"
+
+ printf "%s" "$((
+ font_size*2 + padding_top + padding_bottom + 2 +
+ ($1)*(font_size*2 - 2)
+ ))"
+
+ }
+ # $1: items length
+ get_width()
+ {
+ font_size="$(get_prop "font-size")"
+ padding_left="$(get_prop "padding-left")"
+ padding_right="$(get_prop "padding-right")"
+ printf "%s" "$(($1*(font_size-2) + 2 + padding_left + padding_right))"
+ } ;;
+ "dmenu") ;;
+ *) ;;
+esac
+
+
+main()
+{
+ # shellcheck disable=SC2317
+ case "$MENUCMD" in
+ "tofi")
+ center() { add_option "--anchor=center --width=20%"; }
+
+ horizontal() {
+ add_option "--horizontal=true --height=32"
+ add_option "--result-spacing=12"
+ add_option "--selection-background=#88c0d0"
+ add_option "--selection-background-padding=6,4"
+ add_option "--padding-top=0 --padding-bottom=0"
+ add_option "--margin-top=4"
+ }
+
+ dynamic() {
+ pre_cmd()
+ {
+ max_height="$(get_height 8)"
+ max_width="$(get_width 48)"
+
+ tee "$tmp"
+
+ items_count="$(wc -l < "$tmp")"
+ items_length="$(wc -L < "$tmp")"
+
+ if [ "$long" -ne 1 ]
+ then
+ height="$(get_height "$items_count")"
+ [ "$height" -gt "$max_height" ] && height="$max_height"
+ add_option "--height=$height"
+ fi
+
+ width="$(get_width "$items_length")"
+ [ "$width" -gt "$max_width" ] && width="$max_width"
+
+
+ if [ "$prompt" -eq 1 ]
+ then
+ prompt_width="$(printf "%s" "$prompt_arg" | wc -c)"
+ width="$((width + $(get_width "$prompt_width")))"
+ fi
+
+ add_option "--width=$width"
+ }
+ }
+
+ long() { add_option "--width=100% --height=$(get_height 20)"; }
+
+ input() {
+ add_option "--height=$(get_height 0) --width=$(get_width 24)"
+ pre_filter() { cat /dev/null; }
+ }
+
+ prefix() { add_option '--matching-algorithm=normal'; }
+
+ instant() { add_option "--auto-accept-single=false"; }
+
+ prompt() { add_option '--prompt-text' "$prompt_arg"; }
+
+ numbered() {
+ pre_filter() { awk '{print NR, $0}'; }
+ post_filter() { awk '{print $1}'; }
+ }
+
+ menucmd() { tofi "$@"; }
+ ;;
+
+ "dmenu")
+ horizontal() { add_option "-l 0"; }
+
+ center() { add_option "-c"; }
+
+ long() { add_option "-l 20 -g 1"; }
+
+ input() {
+ pre_filter() { cat /dev/null; }
+ }
+
+ dynamic() {
+ pre_cmd()
+ {
+ tee "$tmp"
+ items_count="$(wc -l < "$tmp")"
+ number="$items_count"
+
+ for i in $(seq $((number/2)))
+ do [ "$((number%i))" -eq 0 ] && factors="$i $factors"
+ done
+
+ min_diff=9999999999
+ for factor in $factors
+ do
+ quotient="$((number/factor))"
+ diff=$((quotient - factor))
+ if [ "$diff" -ge 0 ] && [ "$diff" -lt "$min_diff" ]
+ then
+ columns="$factor"
+ rows="$quotient"
+ min_diff="$diff"
+ fi
+ done
+
+ add_option "-g $columns"
+ add_option "-l $rows"
+ }
+ }
+
+ instant() { add_option "-n"; }
+
+ prefix() { add_option '-x'; }
+
+ prompt() { add_option '-p' "$prompt_arg"; }
+
+ numbered() { add_option "-px"; }
+
+ menucmd() { dmenu "$@"; }
+ ;;
+
+ *)
+ center() { :; }
+
+ horizontal() { :; }
+
+ dynamic() { :; }
+
+ long() { :; }
+
+ input() {
+ pre_filter() { cat /dev/null; }
+ add_option '--print-query'
+ }
+
+ instant() { :; }
+
+ prefix() { :; }
+
+ prompt() { add_option "--prompt" "$prompt_arg"; }
+
+ numbered() {
+ pre_filter() { awk '{print NR, $0}'; }
+ add_option '--with-nth' '2..'
+ post_filter() { awk '{print $1}'; }
+ }
+
+ menucmd() { fzf "$@"; }
+ ;;
+ esac
+
+ for option in $options
+ do eval "$option=0"
+ done
+
+ while getopts ":cdhilop:nrsxv" opt
+ do
+ # shellcheck disable=SC2034
+ case $opt in
+
+ # display horizontal
+ h) horizontal=1 ;;
+ # display centered
+ c) center=1 ;;
+ # take an input and return it on stdout
+ i) input=1 ;;
+ # adjust size and style dynamically
+ d) dynamic=1 ;;
+ p) prompt=1; prompt_arg="$OPTARG";;
+ # long list format
+ l) long=1 ;;
+ # output number of match
+ n) numbered=1 ;;
+ # select an executable from PATH
+ r) shift
+ run | $0 "$@"
+ exit ;;
+ # invert instant select on single match
+ s) instant=1 ;;
+ # invert prefix matching
+ x) prefix=1 ;;
+ v) log_on=1 ;;
+
+ :)
+ logn "Option '-$OPTARG' requires an argument"
+ help
+ exit 1 ;;
+ ?)
+ logn "Invalid option: -$OPTARG"
+ help
+ exit 1 ;;
+ esac
+ done
+
+
+ # conflicts
+ [ "$input" -eq 1 ] && [ "$dynamic" -eq 1 ] && logn "conflicting options." && help && exit 1
+
+ # quit if stdin is empty
+ [ -t 0 ] && [ "$input" -eq 0 ] && logn "Stdin is empty." && help && exit 1
+
+ # call options
+ for option in $options
+ do eval "test \"\$$option\" -eq 1" && $option
+ done
+
+ command -v pre_filter > /dev/null || pre_filter() { cat; }
+ command -v post_filter > /dev/null || post_filter() { cat; }
+
+ which "${MENUCMD:-fzf}" > /dev/null || exit 1
+
+
+
+ if command -v pre_cmd > /dev/null
+ then
+ pre_cmd > "$tmp"
+ logn "menuopts: $menuopts"
+ # shellcheck disable=SC2086
+ pre_filter < "$tmp" | menucmd $menuopts | post_filter
+ else
+ logn "menuopts: $menuopts"
+ # shellcheck disable=SC2086
+ pre_filter | menucmd $menuopts | post_filter
+ fi
+}
+
+main "$@"
diff --git a/bin/menuscripts/mapimg b/bin/menuscripts/mapimg
index 151b8d0..a959d46 100755
--- a/bin/menuscripts/mapimg
+++ b/bin/menuscripts/mapimg
@@ -1,17 +1,8 @@
#!/bin/sh
-if [ -z "$MENUCMD" ]
-then
- menucmd="fzf"
-elif [ "$MENUCMD" = "tofi" ]
-then
- menucmd='tofi --width 700 --height 300 --prompt-text Appimage:'
-else
- menucmd="dmenu -x -l 10 -g 1 -p Appimage:"
-fi
-
dest="$XDG_DATA_HOME"/appimages
appimage="$(find "$dest" -type f -printf "%f\n" |
sed 's/\.[Aa]pp[Ii]mage$//g' |
- $menucmd)"
+ commander -x -l -p "Appimage:")"
+[ "$appimage" ] || exit 1
setsid "$dest/${appimage:-NOSEL}"*
diff --git a/bin/menuscripts/mcurs b/bin/menuscripts/mcurs
index 32f5525..4349e0b 100755
--- a/bin/menuscripts/mcurs
+++ b/bin/menuscripts/mcurs
@@ -1,22 +1,11 @@
#!/bin/sh
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --width 30% --height 20% --padding-left 2% --matching-algorithm normal"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -l 10 -g 1 -x -i"
-else
- menucmd="fzf"
-fi
-
# requirements
-which $MENUCMD firefox > /dev/null ||
- exit 1
+which "$BROWSER" > /dev/null || exit 1
+
+choice="$(find "${1:-$HOME/docs/school}" |
+ grep -i "cursus/index.html" 2> /dev/null |
+ sed "s;$HOME;~;" | commander -x -d -c)"
+[ "$choice" ] && exit 1
-choice="$(find ${1:-$HOME/docs/school} |
- grep "Cursus/index.html" 2> /dev/null |
- sed "s;$HOME;~;" |
- $menucmd)"
-test -z "$choice" && exit 1
-firefox "$choice"
+$BROWSER "$choice"
diff --git a/bin/menuscripts/mdsktp b/bin/menuscripts/mdsktp
index a48aca6..f07fb7b 100755
--- a/bin/menuscripts/mdsktp
+++ b/bin/menuscripts/mdsktp
@@ -1,21 +1,8 @@
#!/bin/sh
# Searches through .desktop files and prompt to launch them via dmenu
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -g 1 -i"
-else
- menucmd="fzf"
-fi
-choice="$(find ~/.local/share/applications \
- -maxdepth 1 \
- -type f \
- -not -iname "wine-extension*" -a -iname "*.desktop" \
- -printf "%f\n" |
- cut -d. -f1 |
- $menucmd)"
-test -z "$choice" && exit 1
+choice="$(find ~/.local/share/applications -maxdepth 1 -type f -not -iname "wine-extension*" |
+ awk '/\/[^.\/]+\.desktop/ {print $(NF-1)}' |
+ commander -s -d -x -c)"
+[ "$choice" ] || exit 1
gtk-launch "$choice"
diff --git a/bin/menuscripts/memoji b/bin/menuscripts/memoji
index d051ad8..9c45950 100755
--- a/bin/menuscripts/memoji
+++ b/bin/menuscripts/memoji
@@ -7,36 +7,27 @@
if [ "$WAYLAND_DISPLAY" ]
then
- copycmd="wl-copy"
+ alias copycmd="wl-copy"
else
- copycmd="xclip -sel c"
-fi
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --width 30% --height 30% --matching-algorithm normal --prompt-text Emoji:"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -l 20 -g 1 -x -i -p Emoji:"
-else
- menucmd="fzf --prompt Emoji:"
+ alias copycmd="xclip -sel c"
fi
set -e
case "$1" in
"list")
data=$(sed '0,/^__DATA__$/d' "$0")
- echo -n "$data"
+ printf "%s" "$data"
;;
"copy")
input=$(tee | cut -f 1 -d ' ')
- if [ ! -z "$input" ]
+ if [ "$input" ]
then
notify-send "dmemoji" "$input <b>copied!</b>"
- echo -n "$input" | $copycmd
+ printf "%s" "$input" | copycmd
fi
;;
"")
- sh $0 list | $menucmd | sh $0 copy
+ sh "$0" list | commander -p "Emoji:" -l -x | sh "$0" copy
;;
esac
diff --git a/bin/menuscripts/mhelp b/bin/menuscripts/mhelp
index e03222b..339d6bf 100755
--- a/bin/menuscripts/mhelp
+++ b/bin/menuscripts/mhelp
@@ -1,33 +1,18 @@
#!/usr/bin/env sh
-OPTIONS="/tmp/dmh_options.txt"
-if [ "$MENUCMD" = "tofi" ]
-then
- program="$(tofi-run --prompt-text "program: ")"
- menucmd="tofi --width 50% --height 30% --matching-algorithm normal --prompt-text $program:"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- program="$(dmenu_path | dmenu -l 4 -g 5 -p "program:")"
- menucmd="dmenu -l 20 -g 1 -x -i -p $program:"
-else
- program="$(dmenu_path | fzf)"
- menucmd="fzf"
-fi
+program="$(commander -r -c -d)"
-test -z "$program" && exit 1
+[ "$program" ] || exit 1
-if $program --help > "$OPTIONS"
-then
- option="$(grep "^ *-[-a-zA-Z0-9]* " "$OPTIONS" |
- tr -s ' ' |
- sort |
- uniq |
- column -l 2 -t |
- $menucmd |
- awk '{print $1}')"
-fi
+option="$("$program" --help |
+ # Parse options
+ grep "^ *-[-a-zA-Z0-9]* " |
+ tr -s ' ' |
+ sort | uniq |
+ column -l 2 -t |
+ commander -l -x -c -d |
+ awk '{print $1}')"
-test -z "$option" && exit 1
+[ "$option" ] || exit 1
-rm -f "$OPTIONS"
-setsid $program $option
+setsid "$program" "$option"
diff --git a/bin/menuscripts/mmpcvol b/bin/menuscripts/mmpcvol
index 0f36e18..239dec3 100755
--- a/bin/menuscripts/mmpcvol
+++ b/bin/menuscripts/mmpcvol
@@ -1,23 +1,13 @@
#!/bin/sh
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --width 5% --height 10% --prompt-text"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -g 2 -l 1 -p"
-else
- menucmd="fzf --prompt"
-fi
-
while true
do
volume="$(mpc volume | awk '{print $2}' | cut -f1 -d'%')"
- choice="$(echo "plus\nmin" |
- $menucmd "$volume" |
+ choice="$(printf "plus\nmin\n" |
+ commander -d -c -p "$volume" |
sed 's/plus/+/;s/min/-/')"
- test -z "$choice" && break
- nb="$($menucmd "$volume$choice" < /dev/null)"
- test -z "$nb" && break
+ [ "$choice" ] || break
+ nb="$(commander -c -p "$volume$choice" -i)"
+ [ "$nb" ] || break
mpc volume "$choice$nb"
done
diff --git a/bin/menuscripts/mpass b/bin/menuscripts/mpass
index a50f0fb..8d5f4eb 100755
--- a/bin/menuscripts/mpass
+++ b/bin/menuscripts/mpass
@@ -1,25 +1,27 @@
#!/usr/bin/env sh
store="${PASSWORD_STORE_DIR:-$HOME/.password-store}"
-lscmd="ls --group-directories-first"
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --prompt pass:"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -l 4 -g 2 -i -p pass:"
-else
- menucmd="fzf --prompt pass:"
-fi
+
+# list passwords, group directories first
+list_pswds()
+{
+ find "$1" \
+ -maxdepth 1 -mindepth 1 \
+ -not -name '.*' -type d -printf "%y\t%f\n" -o \
+ -not -name '.*' -not -type d -printf "%y\t%f\n" |
+ sort -k1 -k2 |
+ cut -f 2 | sed 's/\.gpg$//'
+}
+
while [ -d "$store/$file" ]
do
- choice="$($lscmd "$store/$file" | sed 's/\.gpg$//'| $menucmd)"
- [ "$choice" ] || break
- file="$file/$choice"
+ choice="$(list_pswds "$store/$file" | commander -c -d)"
+ [ "$choice" ] || exit 1
+ [ -z "$file" ] && file="$choice" || file="$file/$choice"
done
+[ "$file" ] || exit 1
+
+pass show -c "$file" || exit 1
+notify-send -t 1000 "mpass" "copied <b>$file</b>"
-test -z "$file" && exit 1
-pass show -c "$file" &&
- if [ -n "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null
-then
+[ "$WAYLAND_DISPLAY" ] && cliphist list >/dev/null && # on wayland and cliphist is running
cliphist list | head -n 1 | cliphist delete
-fi
diff --git a/bin/menuscripts/mpassgen b/bin/menuscripts/mpassgen
index 8384542..51b9bc4 100755
--- a/bin/menuscripts/mpassgen
+++ b/bin/menuscripts/mpassgen
@@ -1,46 +1,21 @@
#!/usr/bin/env sh
-input ()
-{
- # menu prompt for output
- if [ "$MENUCMD" = "tofi" ]
- then
- inp="$(tofi --prompt-text "$1 " </dev/null)"
- elif [ "$MENUCMD" = "dmenu" ]
- then
- inp="$(dmenu -p "$1" < /dev/null)"
- else
- echo -n "$1" >&2
- read inp
- fi
- echo $inp
-}
-# menu select long
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --prompt login:"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -l 10 -g 1 -x -i -p login:"
-else
- menucmd="fzf"
-fi
+input () { commander -c -i -p "$1"; }
-choice="$(echo "multiline\nsingle" | $MENUCMD)"
-test -z "${choice}" && exit 1
+choice="$(printf "multiline\nsingle\n" | commander -c -d)"
+[ "$choice" ] || exit 1
password="$(input "name:")"
-test -z "${password}" && exit 1
+[ "$password" ] || exit 1
-if [ "${choice}" = "multiline" ]
+if [ "$choice" = "multiline" ]
then
- login="$(ls -1 ${PASSWORD_STORE_DIR:=$HOME/.password-store}/e-mails |
- sed 's/\.gpg$//' |
- $menucmd)"
- test -z "${login}" && exit 1
+ login="$(find "${PASSWORD_STORE_DIR:=$HOME/.password-store}"/e-mails -type f -maxdepth 1 -iname "*.gpg" -printf "%f\n" |
+ sed 's/\.gpg$//' | commander -c -d -p 'login:')"
+ [ "$login" ] || exit 1
url="$(input "url:")"
- test -z "${url}" && exit 1
- echo "${password}\nlogin: ${login}\nurl: ${url}" |
+ [ "$url" ] || exit 1
+ printf "%s\nlogin: %s\nurl: %s\n" "${password}" "${login}" "${url}" |
pass insert -mf "${password}"
pass generate -ci "${password}"
else
diff --git a/bin/menuscripts/mpdf b/bin/menuscripts/mpdf
index d67fdae..85debfb 100755
--- a/bin/menuscripts/mpdf
+++ b/bin/menuscripts/mpdf
@@ -1,22 +1,10 @@
#!/bin/sh
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --width 30% --height 30% --matching-algorithm normal --prompt-text pdf:"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -l 10 -g 1 -x -i -p pdf:"
-else
- menucmd="fzf"
-fi
-
-tmp="/tmp/dmpdf"
-find ${1:-$HOME/docs $HOME/dl} 2> /dev/null | grep -E ".+\.pdf" | sort > "$tmp"
-choice="$(sed "s|^$HOME|\~| ; s|\([^/]\)[^/]*/|\1/|g" "$tmp" |
- awk '{printf "%s %s\n", NR ":", $0}' |
- $menucmd |
- grep -o "^[0-9]\+:" |
- cut -f 1 -d :)"
-test -z "$choice" && exit 1
+tmp="/tmp/mpdf"
+choice="$(find ${1:-$HOME/docs $HOME/dl} -iname "*.pdf" 2> /dev/null | sort |
+ tee "$tmp" |
+ sed "s|^$HOME|\~| ; s|\([^/]\)[^/]*/|\1/|g" |
+ commander -x -n)"
file="$(sed -n "${choice}p" "$tmp")"
+[ -r "$file" ] || exit 1
zathura "$file" &
diff --git a/bin/menuscripts/mplay b/bin/menuscripts/mplay
index 08fcc46..e4fca54 100755
--- a/bin/menuscripts/mplay
+++ b/bin/menuscripts/mplay
@@ -1,16 +1,6 @@
#!/bin/sh
-# menu select long
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --width 50% --height 30% --matching-algorithm normal"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -l 10 -g 1 -x -i"
-else
- menucmd="fzf"
-fi
-choice="$(mpc listall | $menucmd)"
-test -z "$choice" &&
- exit 1
-mpc insert "$choice" &&
- mpc next
+choice="$(mpc listall | commander -c -l -d -x)"
+[ "$choice" ] || exit 1
+mpc insert "$choice" || exit 1
+mpc next 2> /dev/null
+mpc play 2> /dev/null
diff --git a/bin/menuscripts/mpower b/bin/menuscripts/mpower
index 443ed54..3b66824 100755
--- a/bin/menuscripts/mpower
+++ b/bin/menuscripts/mpower
@@ -1,14 +1,8 @@
#!/bin/sh
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --width 10% --height 13% --padding-left 2%"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -g 2 -l 2"
-else
- menucmd="fzf"
-fi
+choice="$(printf 'poweroff
+suspend
+hibernate
+reboot
+' | commander -c -d)"
-choices="poweroff\nreboot\nhibernate\nsuspend"
-choice="$(printf "$choices" | $menucmd)"
-test -z "$choice" || systemctl "$choice"
+[ "$choice" ] && systemctl "$choice"
diff --git a/bin/menuscripts/mvid b/bin/menuscripts/mvid
index ca309fb..85187cb 100755
--- a/bin/menuscripts/mvid
+++ b/bin/menuscripts/mvid
@@ -1,27 +1,16 @@
#!/usr/bin/env sh
-tmpfile="/tmp/dmvids"
+tmp="/tmp/dmvids"
dirs="${1:-$HOME/vids $HOME/dl}"
-find -L $dirs 2> /dev/null |
- grep ".\+\.\(webm\|mp4\|mpeg\|mkv\)$" |
- sort > "$tmpfile"
-if [ "$MENUCMD" = "tofi" ]
-then
- menucmd="tofi --width 30% --height 30% --matching-algorithm normal"
-elif [ "$MENUCMD" = "dmenu" ]
-then
- menucmd="dmenu -l 10 -g 1 -x -i"
-else
- menucmd="fzf"
-fi
+choice="$(find -L $dirs 2> /dev/null |
+ grep '^.\+\.\(webm\|mp4\|mpeg\|mkv\)$' |
+ sort | tee "$tmp" |
+ sed "s#^$HOME#\~#;s#\([^/]\)[^/]*/#\1/#g" |
+ commander -d -n -x)"
-choice="$(sed "s|^$HOME|\~| ; s|\([^/]\)[^/]*/|\1/|g" "$tmpfile" |
- awk '{printf "%s %s\n", NR ":", $0}' |
- $menucmd |
- cut -f 1 -d ':')"
-test -z "$choice" &&
- exit 1
+file="$(sed -n "${choice}p" "$tmp")"
+[ -r "$file" ] || exit 1
-mpv "$(sed -n "${choice}p" "$tmpfile")"
+mpv "$file"