summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2023-05-13 15:29:39 +0900
committerRobert Günzler <r@gnzler.io>2023-05-13 15:29:39 +0900
commit06d77d2ba07e6191792a546d7fe15683cc026578 (patch)
tree870afed86e18e76d31aace79ee1e82a31dcbff0e /bin
parented8c20f9a837ac23969cb9d79694bc13a09ac0da (diff)
Revert "bin/menu: switch to tofi"
This reverts commit ed8c20f9a837ac23969cb9d79694bc13a09ac0da.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/menu72
1 files changed, 35 insertions, 37 deletions
diff --git a/bin/menu b/bin/menu
index 22fabdd..23e7801 100755
--- a/bin/menu
+++ b/bin/menu
@@ -1,32 +1,54 @@
-#!/bin/bash
-set -ex
+#!/bin/sh
+set -e
 [ -n "$DEBUG" ] && set -x
 
 # make sure there we are the only running menu
-pgrep tofi >/dev/null && killall -INT tofi
+pgrep -x bemenu >/dev/null && killall -INT bemenu
 
 # always source the config to make sure
-# . "$HOME"/.config/bemenu.conf
+. "$HOME"/.config/bemenu.conf
 
-arg0=tofi
+arg0=bemenu
 prompt=${MENU_PROMPT:-󰈶󰩤}
 args=
 
-tot=$#
 idx=0
-while test $tot -ge $idx; do
+while test $# -gt $idx; do
 	case "$1" in
 	-run)
-		arg0=tofi-run
+		arg0=bemenu-run
 		prompt="󰏌"
 		shift
 		;;
 	-drun)
-		arg0=tofi-drun
-		prompt="󱂬"
+		# arg0=bemenu-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"
@@ -36,34 +58,10 @@ while test $tot -ge $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} --hide-input=true"
+[ -n "${MENU_PASSWORD}" ] && args="${args} --password"
+[ -n "${MENU_POPUP}" ] && args="${args} --center --width-factor 0.5 --border 2 --list 8" # --fixed-height
 exec "${arg0}" --prompt "${prompt}" ${args} "$@"