Skip to content

Commit

Permalink
Add completion scripts to version control
Browse files Browse the repository at this point in the history
It was requested to distribute examples of the completion scripts.
Therefore they are regenerated using `make completion-scripts` and added
under the very same name they have in the master branch.
  • Loading branch information
MaxG87 authored and jmaupetit committed Dec 3, 2019
1 parent c3a1a4d commit b6df0f5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
21 changes: 21 additions & 0 deletions watson.completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
_watson_completion() {
local IFS=$'
'
COMPREPLY=( $( env COMP_WORDS="${COMP_WORDS[*]}" \
COMP_CWORD=$COMP_CWORD \
_WATSON_COMPLETE=complete $1 ) )
return 0
}

_watson_completionetup() {
local COMPLETION_OPTIONS=""
local BASH_VERSION_ARR=(${BASH_VERSION//./ })
# Only BASH version 4.4 and later have the nosort option.
if [ ${BASH_VERSION_ARR[0]} -gt 4 ] || ([ ${BASH_VERSION_ARR[0]} -eq 4 ] && [ ${BASH_VERSION_ARR[1]} -ge 4 ]); then
COMPLETION_OPTIONS="-o nosort"
fi

complete $COMPLETION_OPTIONS -F _watson_completion watson
}

_watson_completionetup;
28 changes: 28 additions & 0 deletions watson.zsh-completion
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
_watson_completion() {
local -a completions
local -a completions_with_descriptions
local -a response
response=("${(@f)$( env COMP_WORDS="${words[*]}" \
COMP_CWORD=$((CURRENT-1)) \
_WATSON_COMPLETE="complete_zsh" \
watson )}")

for key descr in ${(kv)response}; do
if [[ "$descr" == "_" ]]; then
completions+=("$key")
else
completions_with_descriptions+=("$key":"$descr")
fi
done

if [ -n "$completions_with_descriptions" ]; then
_describe -V unsorted completions_with_descriptions -U -Q
fi

if [ -n "$completions" ]; then
compadd -U -V unsorted -Q -a completions
fi
compstate[insert]="automenu"
}

compdef _watson_completion watson;

0 comments on commit b6df0f5

Please sign in to comment.