-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdmenu-wrapper
executable file
·166 lines (146 loc) · 3.49 KB
/
dmenu-wrapper
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/bin/sh
###############################################################################
# dmenu-wrapper
#
# Wrapper for DMENU
#
# -----------------------------------------------------------------------------
# DWM Scripts - wrapper for dwm/dmenu/slock
# (C) 2007-2013 Gerardo García Peña
# Programmed by Gerardo García Peña
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
###############################################################################
. dwm-config-read
IFS="
"
PATH="$PATH:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$HOME/bin"
DMENUCFG=`search_config_file "dmenu-config"`
SELECTED_MONITOR="0"
if [ "$DMENUCFG" ]; then
CMLIST=`cat "$DMENUCFG"`
else
CMLIST="
# Select your favourite programs. If a program needs administration
# privileges (su or sudo), add an exclamation mark before.
aterm
chromium-browser
firefox
gnome-terminal
nautilus --no-desktop
!poweroff
!reboot
dwm-screenshot
dwm-windowshot
dwm-xterm
!wireshark
xcalc
xclock
xterm"
fi
launch_dmenu()
{
local i C
for i in $CMLIST; do
C="`echo "$i" | sed 's# .*$##' | sed 's#^!##'`"
which "$C" > /dev/null 2>&1 && basename "$C"
done | dmenu
}
is_cmlist_entry()
{
for i in $CMLIST; do
echo "$i"
done | sed 's#^!##' | grep "^$1"
}
choose_command()
{
local i C T
C="`launch_dmenu`"
if [ "$C" ] && T=`is_cmlist_entry "$C"`; then
C="$T"
fi
echo "$C"
}
need_su()
{
local i C
C="$1"
if [ "$C" ] && echo "$CMLIST" | grep "^!.*$C" > /dev/null 2>&1; then
return 0
else
return 1
fi
}
shutdown_action()
{
if [ "$1" = "poweroff" -o "$1" = "reboot" ]; then
return 0
else
return 1
fi
}
while test "$1"; do
PARAMETER="$1"
shift
case "$1" in
-m)
SELECTED_MONITOR="$1"
shift
if [ -z "$SELECTED_MONITOR" ] \
|| echo "$SELECTED_MONITOR" | grep -v '^\(0\|[1-9][0-9]*\)' > /dev/null 2>&1; then
error "Invalid selected monitor '$SELECTED_MONITOR'."
exit 1
fi
;;
*)
error "Unknown parameter '$PARAMETER'."
exit 1
esac
done
CMLIST=`echo "$CMLIST" | grep -v '^ *\(#.*\)\?$' | sed 's#\(^ \+\| \+$\)##'`
if [ "$DMN_HOME_BIN" -a -d ~/bin ]; then
for BIN in `find ~/bin -type f -executable`; do
BIN="`basename "$BIN"`"
if ! is_cmlist_entry "$BIN"; then
echo "Add [$BIN]"
CMLIST="$CMLIST$IFS$BIN"
fi
done
fi
CH=`choose_command`
if [ -z "$CH" ]; then
# if execution is at this point, it means that user pressed ESC
exit 1
fi
if echo $CH | grep -v ' ' > /dev/null 2>&1; then
CM=`which "$CH"`
else
CM="$CH"
fi
if need_su "$CH"; then
CM=`dwm-sudo $CM`
fi
if shutdown_action "$CH"; then
dwm-shutdown "$CH"
else
if [ -z "$CM" ]; then
msg "I don't know nothing about '$CH'. Leave Britney alone."
else
msg "Launching: $CM"
sh -c "$CM" &
fi
fi
exit 0