summary refs log tree commit diff
path: root/bin/menu
blob: b3a87bc0592cbad067228002a899f065c9f5c36e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/sh
set -e
[ -n "$DEBUG" ] && set -x

# make sure there we are the only running menu
pgrep bemenu >/dev/null && pkill -f bemenu

# always source the config to make sure
. "$HOME"/.config/bemenu.conf

arg0=bemenu
MENU_PROMPT=${MENU_PROMPT:-}
MENU_FROM_PATH=${MENU_FROM_PATH:-}

# this is used by -run to combine desktop files and PATH binaries
if [ -n "$MENU_FROM_PATH" ]; then
	(cat ; (fd -tf -tl -tx . $(printf "%s" "$PATH" | tr : ' ') -x printf "%s\n" {/} | sort -u)) |
		env -u MENU_FROM_PATH $0
	exit $?
fi

idx=0
while test $# -gt $idx; do
	case "$1" in
	-run)
		# arg0=bemenu-run
		export MENU_FROM_PATH=1 # reexec
		arg0="j4-dmenu-desktop --no-generic --dmenu=$0 --term=foot"
		shift
		;;
	-drun)
		arg0="j4-dmenu-desktop --no-generic --dmenu=$0 --term=foot"
		shift
		;;
	-p)
		shift
		MENU_PROMPT="$1"
		shift
		;;
	-x)
		shift
		BEMENU_OPTS="${BEMENU_OPTS} --password"
		;;
	esac
	idx=$((idx + 1))
done

if [ -n "${MENU_POPUP}" ]; then
	BEMENU_OPTS="${BEMENU_OPTS} --center --width-factor 0.5 --border 2 --list 8" # --fixed-height
fi

BEMENU_OPTS="${BEMENU_OPTS} --prompt \"${MENU_PROMPT}\""

BEMENU_OPTS="${BEMENU_OPTS} $*"

exec ${arg0}