-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update completion scripts for urfave/cli/v3
follow up of cab383f
- Loading branch information
1 parent
964e31d
commit ffd3b9e
Showing
4 changed files
with
64 additions
and
45 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 |
---|---|---|
@@ -1,35 +1,36 @@ | ||
#! /bin/bash | ||
|
||
: ${PROG:=fhome} | ||
#!/usr/bin/env bash | ||
|
||
# Macs have bash3 for which the bash-completion package doesn't include | ||
# _init_completion. This is a minimal version of that function. | ||
_cli_init_completion() { | ||
__fallback_init_completion() { | ||
COMPREPLY=() | ||
_get_comp_words_by_ref "$@" cur prev words cword | ||
} | ||
|
||
_cli_bash_autocomplete() { | ||
__start-fhome() { | ||
if [[ "${COMP_WORDS[0]}" != "source" ]]; then | ||
local cur opts base words | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
if declare -F _init_completion >/dev/null 2>&1; then | ||
_init_completion -n "=:" || return | ||
else | ||
_cli_init_completion -n "=:" || return | ||
__fallback_init_completion -n "=:" || return | ||
fi | ||
words=("${words[@]:0:$cword}") | ||
if [[ "$cur" == "-"* ]]; then | ||
requestComp="${words[*]} ${cur} --generate-bash-completion" | ||
requestComp="${words[*]} ${cur} --generate-shell-completion" | ||
else | ||
requestComp="${words[*]} --generate-bash-completion" | ||
requestComp="${words[*]} --generate-shell-completion" | ||
fi | ||
opts=$(eval "${requestComp}" 2>/dev/null) | ||
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
return 0 | ||
fi | ||
} | ||
|
||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG | ||
unset PROG | ||
if [[ $(type -t compopt) = "builtin" ]]; then | ||
complete -o default -F __start-fhome fhome | ||
else | ||
complete -o default -o nospace -F __start-fhome fhome | ||
fi |
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 |
---|---|---|
@@ -1,35 +1,36 @@ | ||
#! /bin/bash | ||
|
||
: ${PROG:=fhomed} | ||
#!/usr/bin/env bash | ||
|
||
# Macs have bash3 for which the bash-completion package doesn't include | ||
# _init_completion. This is a minimal version of that function. | ||
_cli_init_completion() { | ||
__fallback_init_completion() { | ||
COMPREPLY=() | ||
_get_comp_words_by_ref "$@" cur prev words cword | ||
} | ||
|
||
_cli_bash_autocomplete() { | ||
__start-fhomed() { | ||
if [[ "${COMP_WORDS[0]}" != "source" ]]; then | ||
local cur opts base words | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
if declare -F _init_completion >/dev/null 2>&1; then | ||
_init_completion -n "=:" || return | ||
else | ||
_cli_init_completion -n "=:" || return | ||
__fallback_init_completion -n "=:" || return | ||
fi | ||
words=("${words[@]:0:$cword}") | ||
if [[ "$cur" == "-"* ]]; then | ||
requestComp="${words[*]} ${cur} --generate-bash-completion" | ||
requestComp="${words[*]} ${cur} --generate-shell-completion" | ||
else | ||
requestComp="${words[*]} --generate-bash-completion" | ||
requestComp="${words[*]} --generate-shell-completion" | ||
fi | ||
opts=$(eval "${requestComp}" 2>/dev/null) | ||
COMPREPLY=($(compgen -W "${opts}" -- ${cur})) | ||
return 0 | ||
fi | ||
} | ||
|
||
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG | ||
unset PROG | ||
if [[ $(type -t compopt) = "builtin" ]]; then | ||
complete -o default -F __start-fhomed fhomed | ||
else | ||
complete -o default -o nospace -F __start-fhomed fhomed | ||
fi |
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 |
---|---|---|
@@ -1,17 +1,25 @@ | ||
#compdef fhome | ||
compdef _fhome fhome | ||
|
||
local -a opts | ||
local cur | ||
cur=${words[-1]} | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") | ||
else | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") | ||
fi | ||
_fhome() { | ||
local -a opts | ||
local cur | ||
cur=${words[-1]} | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-shell-completion)}") | ||
else | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-shell-completion)}") | ||
fi | ||
|
||
if [[ "${opts[1]}" != "" ]]; then | ||
_describe 'values' opts | ||
else | ||
_files | ||
fi | ||
if [[ "${opts[1]}" != "" ]]; then | ||
_describe 'values' opts | ||
else | ||
_files | ||
fi | ||
} | ||
|
||
# Don't run the completion function when being source-ed or eval-ed. | ||
# See https://github.com/urfave/cli/issues/1874 for discussion. | ||
if [ "$funcstack[1]" = "_fhome" ]; then | ||
_fhome | ||
fi |
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 |
---|---|---|
@@ -1,16 +1,25 @@ | ||
#compdef fhomed | ||
compdef _fhomed fhomed | ||
|
||
local -a opts | ||
local cur | ||
cur=${words[-1]} | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") | ||
else | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") | ||
fi | ||
_fhomed() { | ||
local -a opts | ||
local cur | ||
cur=${words[-1]} | ||
if [[ "$cur" == "-"* ]]; then | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-shell-completion)}") | ||
else | ||
opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-shell-completion)}") | ||
fi | ||
|
||
if [[ "${opts[1]}" != "" ]]; then | ||
_describe 'values' opts | ||
else | ||
_files | ||
fi | ||
} | ||
|
||
if [[ "${opts[1]}" != "" ]]; then | ||
_describe 'values' opts | ||
else | ||
_files | ||
# Don't run the completion function when being source-ed or eval-ed. | ||
# See https://github.com/urfave/cli/issues/1874 for discussion. | ||
if [ "$funcstack[1]" = "_fhomed" ]; then | ||
_fhomed | ||
fi |