-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdmenu_apps
executable file
·30 lines (25 loc) · 1.05 KB
/
dmenu_apps
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
#!/bin/bash
DESKTOP_PATHS="/usr/share/applications/*.desktop /usr/local/share/applications/*.desktop"
function exit_on_empty() {
if [ "x$1" == "x" ]; then
exit 1
fi
}
while [ 1 ]; do
category=`find /usr/share/applications/ $DESKTOP_PATHS -iname *.desktop | xargs grep 'Categories=' | cut -d '=' -f2 | tr ';' '\n' | cut -d ';' -f2 | sort | uniq | grep -v '^$' | dmenu $@ -i`
if [ "x$category" == "x" ]; then
exit 1 #Exit menu
fi
while [ 1 ]; do
name=`grep -H -R '^Name[=]\|^Categories[=]' $DESKTOP_PATHS | grep $category | cut -d ':' -f1 | xargs grep -m 1 '^Name=' | cut -d '=' -f2 | sort | uniq | grep -v '^$' | dmenu $@ -i`
if [ "x$name" == "x" ]; then
break; #Go back to top level menu
fi
exec=`grep -H -R -m 1 '^Name='"$name"'$' $DESKTOP_PATHS | cut -d ':' -f1 | xargs grep -m1 '^Exec=' | cut -d '=' -f2 | cut -d '%' -f1 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' | head -1`
if [ "x$exec" == "x" ]; then
continue; #Return to names menu
fi
nohup $exec &
exit 0 #exit menu successfully
done
done