Created
November 3, 2013 20:42
-
-
Save evanpurkhiser/7294574 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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