Skip to content

Instantly share code, notes, and snippets.

@jacaetevha
Created April 19, 2013 15:17
Show Gist options
  • Save jacaetevha/5421036 to your computer and use it in GitHub Desktop.
Save jacaetevha/5421036 to your computer and use it in GitHub Desktop.
Guardfile bash completion
# bash completion for Guard groups
#
# INSTALL
#
# Place in your bash completions.d and/or source in your .bash_profile
#
# USAGE
#
# Type 'guard' and hit tab twice to get completions.
# To clear the cache, run guard_cache_clear() in your shell.
#
function _guard_cache_path() {
# If in a Rails app, put the cache in the cache dir
# so version control ignores it
if [ -e 'tmp/cache' ]; then
prefix='tmp/cache/'
fi
echo "${prefix}.guard_t_cache"
}
function guard_cache_store() {
grep group Guardfile | awk '{print $2}' | tr -d ':' > "$(_guard_cache_path)"
}
function guard_cache_clear() {
rm -f .guard_t_cache
rm -f tmp/cache/.guard_t_cache
}
# export COMP_WORDBREAKS=${COMP_WORDBREAKS/\:/}
function _guardcomplete() {
# error if no guardfile
if [ ! -e guardfile ]; then
echo "missing Guardfile"
return 1
fi
# build cache if missing
if [ ! -e "$(_guard_cache_path)" ]; then
guard_cache_store
fi
local groups=`awk '{print $1}' "$(_guard_cache_path)"`
COMPREPLY=($(compgen -W "${groups}" -- ${COMP_WORDS[COMP_CWORD]}))
return 0
}
complete -o default -o nospace -F _guardcomplete guard
# uncomment the following if you want the completion to be enabled with "bundle exec"
# complete -o default -o nospace -F _guardcomplete bundle exec guard
# uncomment the following if you like to alias "bundle exec" as "be"
# complete -o default -o nospace -F _guardcomplete be guard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment