summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2015-09-07 17:59:45 +0200
committerGravatar Tom van der Lee <t0m.vd.l33@gmail.com>2015-09-07 21:25:46 +0200
commit720477b453555b589b9c3fe0518ccb98f8942edd (patch)
treeee96ac7630cfb9c2caa46def6b724efcdd90dc43
parent36f214b062a63d1cd5897a04d1014d63240cf730 (diff)
downloaddmenu_app-720477b453555b589b9c3fe0518ccb98f8942edd.tar.gz
dmenu_app-720477b453555b589b9c3fe0518ccb98f8942edd.tar.bz2
dmenu_app-720477b453555b589b9c3fe0518ccb98f8942edd.zip
Added initial code
-rwxr-xr-xdmenu_app38
1 files changed, 38 insertions, 0 deletions
diff --git a/dmenu_app b/dmenu_app
new file mode 100755
index 0000000..ded6b6d
--- /dev/null
+++ b/dmenu_app
@@ -0,0 +1,38 @@
1#!/usr/bin/env bash
2
3add_to_cache(){
4 application="$1"
5
6 names=$(sed -n "s/^Name=\(.*\)$/\1/p" "$application")
7 executables=$(sed -n "s/^Exec=\(.*\)$/\1/p" "$application")
8
9 if [ -n "$names" ] && [ -n "$executables" ]; then
10 name=$(echo "$names" | sed "1!d")
11 executable=$(echo "$executables" | sed "1!d")
12
13 if [ -n "$name" ] && [ -n "$executable" ]; then
14 echo -e "$name:$executable" >> "$cache_file"
15 fi
16 fi
17}
18
19usrlocations=$(echo {/usr,/usr/local,$HOME/.local,$HOME/.local/usr,$HOME/.local/usr/local}/share/applications)
20desktop_files=$(find $usrlocations -name "*.desktop" 2> /dev/null)
21checksum=$(echo $desktop_files | sha1sum)
22cache_file="$HOME/.cache/dmenu_app"
23if [ ! -f "$cache_file" ] || [ "$(head -n1 "$cache_file")" != "$checksum" ]; then
24 echo "Updating cache file"
25 echo "$checksum" > "$cache_file"
26 while read application; do
27 add_to_cache "$application" &
28 done < <(echo "$desktop_files")
29 wait
30fi
31
32choice=$(cat $cache_file | tail -n +2 | cut -d: -f1 | sort -h | dmenu $@)
33if [ -n "$choice" ]; then
34 command=$(sed -n "s/^$choice:\(.*\)$/\1/p" "$cache_file")
35 if [ -n "$command" ]; then
36 echo "$command" | sh
37 fi
38fi