diff options
| author | Robert Günzler <r@gnzler.io> | 2023-05-13 15:29:26 +0900 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2023-05-13 15:29:26 +0900 |
| commit | ed8c20f9a837ac23969cb9d79694bc13a09ac0da (patch) | |
| tree | 2eb89a9f667ce7c38889abfc7ea18f081216b605 | |
| parent | 70abde6d16965bcf922789846dd0655584a4bfe5 (diff) | |
bin/menu: switch to tofi
Signed-off-by: Robert Günzler <r@gnzler.io>
| -rwxr-xr-x | bin/menu | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/bin/menu b/bin/menu index 23e7801..22fabdd 100755 --- a/bin/menu +++ b/bin/menu @@ -1,54 +1,32 @@ -#!/bin/sh -set -e +#!/bin/bash +set -ex [ -n "$DEBUG" ] && set -x # make sure there we are the only running menu -pgrep -x bemenu >/dev/null && killall -INT bemenu +pgrep tofi >/dev/null && killall -INT tofi # always source the config to make sure -. "$HOME"/.config/bemenu.conf +# . "$HOME"/.config/bemenu.conf -arg0=bemenu +arg0=tofi prompt=${MENU_PROMPT:-} args= +tot=$# idx=0 -while test $# -gt $idx; do +while test $tot -ge $idx; do case "$1" in -run) - arg0=bemenu-run + arg0=tofi-run prompt="" shift ;; -drun) - # arg0=bemenu-drun - # prompt="" + arg0=tofi-drun + prompt="" shift - desktopfiles() { - fd -e desktop . \ - /usr/share/applications/ \ - /usr/local/share/applications/ \ - /var/lib/flatpak/app/*/current/active/export/share/applications/ \ - "$XDG_DATA_HOME"/applications/ 2>/dev/null || true - } - list_apps() { - desktopfiles | - xargs -I{} awk -F= '/^Name=/{ print $2;exit; }' {} | - sort -u - } - get_desktopfile() { - desktopfiles | - xargs -I{} awk -v name="$1" -F= '/^Name=/{ if($2==name) print FILENAME }' {} | - sort -u | - head -n1 - } - app=$(list_apps | MENU_PROMPT="" "$0") - [ -z "$app" ] && exit 0 - desktopfile=$(get_desktopfile "$app") - [ -z "$desktopfile" ] && exit 0 - nohup xdg-exec "$desktopfile" "$@" >/dev/null 2>&1 & - exit 0 ;; + # dmenu compat -p) shift prompt="$1" @@ -58,10 +36,34 @@ while test $# -gt $idx; do shift MENU_PASSWORD=1 ;; + -i) + shift + ;; + # bemenu compat + -l*) + num=$(cut -c3- <<<"$1") + shift + if [ -z "$num" ]; then + num=$1 + shift + fi + args="$args --num-results=$num" + ;; + --prompt) + shift + args="$args --prompt-text" + ;; + --ifne) + shift + args="$args --require-match=true" + ;; + --accept-single) + shift + args="$args --autoselect=true" + ;; esac idx=$((idx + 1)) done -[ -n "${MENU_PASSWORD}" ] && args="${args} --password" -[ -n "${MENU_POPUP}" ] && args="${args} --center --width-factor 0.5 --border 2 --list 8" # --fixed-height +[ -n "${MENU_PASSWORD}" ] && args="${args} --hide-input=true" exec "${arg0}" --prompt "${prompt}" ${args} "$@" |