Skip to content

Instantly share code, notes, and snippets.

@tylerbrazier
Last active May 2, 2021 19:56
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 tylerbrazier/10851358ac11cf6d972f7df306f3075c to your computer and use it in GitHub Desktop.
Save tylerbrazier/10851358ac11cf6d972f7df306f3075c to your computer and use it in GitHub Desktop.
#!/bin/sh
cachedir="${XDG_CACHE_HOME:-"$HOME/.cache"}"
pathcache="$cachedir/dmenu_run"
histcache="$cachedir/dmenu_history"
[ ! -e "$cachedir" ] && mkdir -p "$cachedir"
[ ! -e "$histcache" ] && touch "$histcache"
cmd="$( (tac "$histcache"; dmenu_path;) | dmenu "$@" )"
test -n "$cmd" || exit
# remove the cmd from caches before appending to avoid duplicates
for file in "$histcache" "$pathcache"; do
line="$(grep -nxF "$cmd" "$file")"
test -n "$line" && sed -e "${line%%:*}d" -i "$file"
done
echo "$cmd" | tee -a "$histcache"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment