forked from jgmenu/jgmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jgmenu_run
executable file
·104 lines (90 loc) · 3.08 KB
/
jgmenu_run
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/sh
: ${JGMENU_EXEC_DIR=~/src/jgmenu}
export PATH=$JGMENU_EXEC_DIR:$PATH
JGMENU_LOCKFILE=~/.jgmenu-lockfile
die () {
printf "fatal: %s\n" "$1"
exit 1
}
usage () {
printf "usage: jgmenu_run\n"
printf " jgmenu_run <command> [<args>]\n\n"
printf "Top level convenience wrapper for jgmenu\n\n"
printf "If no 'command' or argument is specified, jgmenu_run does one of the following:\n"
printf " - Shows the menu if an instance of jgmenu is already running\n"
printf " - Starts jgmenu in 'stay-alive' mode (i.e. as a long-running application)\n"
printf " using pmenu unless otherwise specified by 'csv_cmd' in jgmenurc\n\n"
printf "Valid 'commands' include:\n"
printf " start Start menu in 'hidden' mode\n"
printf " init Create or amend config file\n"
printf " pmenu Run menu based on .desktop and .directory files\n"
printf " xdg Run menu based on .desktop, .directory and .menu files\n"
printf " lx Run XDG compliant menu created using LXDE's libmenu-cache\n"
printf " csv Run menu based on .csv file\n"
printf " ob Run menu based openbox menu-file\n\n"
exit 0
}
print_exec_path () {
printf "%b\n" "${JGMENU_EXEC_DIR}"
exit 0
}
# Pipe to UNIX socket if tint2 button was used.
send_tint2_env_vars_to_jgmenu () {
# Check set/unset with ${parameter+word}
test -z ${TINT2_BUTTON_ALIGNED_X+x} && return
printf "%b" \
"TINT2_BUTTON_ALIGNED_X1=${TINT2_BUTTON_ALIGNED_X1}\n" \
"TINT2_BUTTON_ALIGNED_X2=${TINT2_BUTTON_ALIGNED_X2}\n" \
"TINT2_BUTTON_ALIGNED_Y1=${TINT2_BUTTON_ALIGNED_Y1}\n" \
"TINT2_BUTTON_ALIGNED_Y2=${TINT2_BUTTON_ALIGNED_Y2}\n" \
"TINT2_BUTTON_PANEL_X1=${TINT2_BUTTON_PANEL_X1}\n" \
"TINT2_BUTTON_PANEL_X2=${TINT2_BUTTON_PANEL_X2}\n" \
"TINT2_BUTTON_PANEL_Y1=${TINT2_BUTTON_PANEL_Y1}\n" \
"TINT2_BUTTON_PANEL_Y2=${TINT2_BUTTON_PANEL_Y2}" \
| ${JGMENU_EXEC_DIR}/jgmenu-socket
}
remove_lockfile () {
rm -f "${JGMENU_LOCKFILE}"
printf "warn: %b\n" "found old lockfile; lockfile removed"
}
# "jgmenu_run" with no arguments specified
if test $# -lt 1
then
# A primary objective here is to keep 'awake' quick
# Checking if the lockfile exists is much quicker than
# 'pgrep -x jgmenu' (30ms on my machine) or similar.
if test -e ${JGMENU_LOCKFILE}
then
send_tint2_env_vars_to_jgmenu
if killall -SIGUSR1 jgmenu >/dev/null 2>&1
then
exit 0
else
# We should not get to here unless
# - there has been a crash (e.g. ASAN related)
# - lockfile was left from a jgmenu compiled before
# commit e3cb35 when we started to handle SIGTERM
# and SIGINT
remove_lockfile
fi
fi
cmd=$(jgmenu_run config --get csv_cmd)
test -z "${cmd}" && cmd="jgmenu_run parse-pmenu"
# Run it through a shell enable tilde and variable expansion
sh -c "${cmd} | jgmenu"
exit 0
fi
test "$1" = "--help" && usage
test "$1" = "--exec-path" && print_exec_path
cmd="$1"
cmds="jgmenu-${cmd} jgmenu-${cmd}.sh jgmenu-${cmd}.py"
shift
for c in ${cmds}
do
if type ${c} >/dev/null 2>&1
then
exec ${c} "$@"
exit 0
fi
done
die "'${cmd}' is not a jgmenu_run command"