Skip to content

Commit

Permalink
Merge pull request 99designs#306 from segevfiner/shell-completions
Browse files Browse the repository at this point in the history
Add custom shell completion scripts
  • Loading branch information
mtibben authored Nov 16, 2018
2 parents 65ded8e + 4340858 commit 36015eb
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 36015eb

Please sign in to comment.