Skip to content

Instantly share code, notes, and snippets.

@illustris
Created December 16, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illustris/489298eaae2b9d668189c82a5ddd4f49 to your computer and use it in GitHub Desktop.
Save illustris/489298eaae2b9d668189c82a5ddd4f49 to your computer and use it in GitHub Desktop.
dmenu + history
#!/bin/sh
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
histsize=50
if [ -d "$cachedir" ]; then
cache=$cachedir/emenu
hist=$cachedir/emenu_hist
else
cache=$HOME/.emenu_cache # if no xdg dir, fall back to dotfile in ~
hist=$HOME/.emenu_cache_hist # if no xdg dir, fall back to dotfile in ~
fi
if [ ! -e "$hist" ]; then
touch "$hist"
echo foo
fi
cmd=$(
IFS=:
if stest -dqr -n "$cache" $PATH; then
(tac "$hist" ; stest -flx $PATH | sort -u | tee "$cache" ) | dmenu "$@"
else
(tac "$hist"; cat "$cache") | dmenu "$@"
fi
)
#echo "$cmd" | ${SHELL:-"/bin/sh"} &
i3-msg "exec $cmd"
sed -i -e "/^${cmd}$/d;${histsize}q" "$hist"
echo "$cmd" >> "$hist"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment