Skip to content

Commit

Permalink
Add custom shell completion scripts
Browse files Browse the repository at this point in the history
They are based on the shell completion scripts generated by kingpin in
alecthomas/kingpin#252. Modified to complete commands after '--'.

Fixes 99designs#70
  • Loading branch information
segevfiner committed Oct 30, 2018
1 parent c506333 commit 4340858
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aws-vault
aws-vault-*
/aws-vault
/aws-vault-*
.DS_Store
17 changes: 17 additions & 0 deletions completions/bash/aws-vault
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
_aws-vault_bash_autocomplete() {
local i cur prev opts base

for (( i=1; i < COMP_CWORD; i++ )); do
if [[ ${COMP_WORDS[i]} == -- ]]; then
_command_offset $i+1
return
fi
done

COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$( ${COMP_WORDS[0]} --completion-bash "${COMP_WORDS[@]:1:$COMP_CWORD}" )
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
complete -F _aws-vault_bash_autocomplete -o default aws-vault
24 changes: 24 additions & 0 deletions completions/zsh/_aws-vault
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#compdef aws-vault

_aws-vault() {
local i
for (( i=2; i < CURRENT; i++ )); do
if [[ ${words[i]} == -- ]]; then
shift $i words
(( CURRENT -= i ))
_normal
return
fi
done

local matches=($(${words[1]} --completion-bash "${(@)words[1,$CURRENT]}"))
compadd -a matches

if [[ $compstate[nmatches] -eq 0 && $words[$CURRENT] != -* ]]; then
_files
fi
}

if [[ "$(basename -- ${(%):-%x})" != "_aws-vault" ]]; then
compdef _aws-vault aws-vault
fi

0 comments on commit 4340858

Please sign in to comment.