Skip to content

Instantly share code, notes, and snippets.

@grubernd
Last active August 6, 2020 08:20
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 grubernd/debe9075b7bb22b0494fcac2c8574894 to your computer and use it in GitHub Desktop.
Save grubernd/debe9075b7bb22b0494fcac2c8574894 to your computer and use it in GitHub Desktop.
#!/bin/bash
#------------------------------------------------------------------------------
# > Copyright (C) 2017-2020 GRUBERND http://grubernd.at
# > released under an MIT License
#
# ## Open files via dmenu
#
# _Revision 2020-07-29_
#
# ### 20.07
# + Improve find command for less clutter
# + Fix bug when no previous cache exists
#
# ### 17.05
# + Initial version
#
# Dependencies:
# + `dmenu`
# + `xargs`
# + `exo-open` from the exo-utils package
#------------------------------------------------------------------------------
_dmenu_write_new_cache() {
local cache_file="$1"
find $HOME/ -path "$HOME/.*" -prune \
-o -iname "*mkd" \
-o -iname "*ods" \
-o -iname "*txt" \
|grep -v "$HOME/\." \
|sort -u \
|tee "$cache_file"
}
#------------------------------------------------------------------------------
_dmenu_text_cache() {
# where is the cache file?
# if no xdg dir, fall back to dotfile in ~
cachedir=${XDG_CACHE_HOME:-"$HOME/.cache"}
if [ -d "$cachedir" ]; then
cache="$cachedir/dmenu_home_text"
else
cache="$HOME/.dmenu_home_text"
fi
if [ ! -f "$cache" ]; then
_dmenu_write_new_cache "$cache"
fi
# recreate the cache if it is older than 6 hours else just cat it
if [ -f $(find $cache -mmin +360) ]; then
_dmenu_write_new_cache "$cache"
else
cat "$cache"
fi
}
#------------------------------------------------------------------------------
# MAIN
_dmenu_text_cache | dmenu -i -l 20 -sb '#c33' -sf '#fff' | xargs exo-open
#------------------------------------------------------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment