Skip to content

Instantly share code, notes, and snippets.

@akheron
Created January 2, 2012 07:28
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 akheron/1549712 to your computer and use it in GitHub Desktop.
Save akheron/1549712 to your computer and use it in GitHub Desktop.
bash completion for sala
#!bash
_sala() {
local IFS=$'\n' dir=${SALADIR:-.} cur
if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
cur=${COMP_WORDS[$COMP_CWORD]}
else
_get_comp_words_by_ref cur
fi
# Not initialized, bail out
[ ! -f "$dir/.salakey" ] && return
# Skip dotfiles, e.g. .salakey
local names=$(cd $dir && compgen -f -- "$cur" | grep -v '^\.')
COMPREPLY=($(for name in $names; do
[ -d "$dir/$name" ] \
&& echo "${name}/" \
|| echo "$name " # Add a space after filenames
done))
}
complete -o nospace -F _sala sala
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment