-
-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add completion scripts to version control
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
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
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
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; |
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
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; |