Skip to content

Instantly share code, notes, and snippets.

@evanpurkhiser
Created November 3, 2013 20:42
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 evanpurkhiser/7294574 to your computer and use it in GitHub Desktop.
Save evanpurkhiser/7294574 to your computer and use it in GitHub Desktop.
#!/bin/bash
_dots_completions()
{
local base_cmds=(groups diff files install help)
local base_flags=(-c --config)
local cur=${COMP_WORDS[$COMP_CWORD]}
local prev=${COMP_WORDS[$COMP_CWORD-1]}
# Determine the command position
local cmd_index=1
[[ ${COMP_WORDS[1]} == "-c" ]] && cmd_index=3
# Include additional flags for the first word
if [[ $COMP_CWORD == 1 ]]
then
COMPREPLY=( $(compgen -W "${base_cmds[*]} ${base_flags[*]}" -- $cur) )
return
fi
# Perform file completion for the config option
if [[ $cmd_index > $COMP_CWORD ]]
then
compopt -o default
return
fi
# Perform completion on the base command
if [[ $COMP_CWORD == $cmd_index ]]
then
COMPREPLY=( $(compgen -W "${base_cmds[*]}" -- $cur) )
return
fi
# Perform completion for sub-commands
case "${COMP_WORDS[$cmd_index]}" in
groups)
COMPREPLY=( $(compgen -W "known current clear set" -- $cur) )
;;
diff)
COMPREPLY=( $(compgen -W "$(dots files)" -- $cur) )
;;
files)
COMPREPLY=()
;;
install)
COMPREPLY=()
;;
esac
}
complete -F _dots_completions dots
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment