Permalink
Browse files

dmenu_launch: refactor, and include cache regeneration

  • Loading branch information...
1 parent 0095023 commit 0cb7ba9d936d66d1fb2e8824e5435156d6839779 @falconindy committed Jul 25, 2011
Showing with 32 additions and 1 deletion.
  1. +32 −1 dmenu_launch
View
33 dmenu_launch
@@ -7,10 +7,41 @@ normfgcolor="#FFFFFF"
selbgcolor="#3465A4"
selfgcolor="#FFFFFF"
-cmd=$(dmenu_path | dmenu -i -b -fn $font -nb $normbgcolor -nf $normfgcolor -sb $selbgcolor -sf $selfgcolor)
+cache=~/.cache/dmenu
+dmenu_opts=(
+ -i
+ -b
+ -fn "$font"
+ -nb "$normbgcolor"
+ -nf "$normfgcolor"
+ -sb "$selbgcolor"
+ -sf "$selfgcolor"
+)
+
+regen_cache() {
+ find "${paths[@]}" -maxdepth 1 \( -type f -o -type l \) -executable -printf '%f\n' |
+ sort -u >"$cache"
+}
+
+
+getbins() {
+ IFS=':' read -r -a paths <<< "$PATH"
+ for path in "${paths[@]}"; do
+ if [[ $path -nt $cache ]]; then
+ regen_cache
+ break
+ fi
+ done
+ cat "$cache"
+}
+
+cmd=$(getbins | dmenu "${dmenu_opts[@]}")
+
+# dispatch!
case $cmd in
ncmpcpp|htop|vim) exec $term -name $cmd -e $cmd ;;
tmux) exec $term -name tmux -geometry 122x77 -e tmux -L main attach ;;
*) exec $cmd
esac
+

0 comments on commit 0cb7ba9

Please sign in to comment.