Re: [Fish-users] gcloud completions
Status: Beta
Brought to you by:
liljencrantz
|
From: Johannes A. <ac...@gm...> - 2024-03-21 07:52:26
|
On Wed, Mar 20, 2024 at 09:51:06PM +0000, Peter Flood wrote:
> Hi all,
>
> Does anyone know a way to get gcloud (& gsutil etc etc) completions working
> in fish? There are bash and zsh completions, any way to convert them?
Ideally these commands provide native fish completions, (if they're
use a framework like Cobra, that should be given) but you can also
reuse bash completions like below.
Would be nice to be able to use something like this as general fallback
but I don't know yet if this is robust enough.
Also fish probably still wants to know whether to include file
completions or not (as indicated by the `-f` option)
for cmd in gcloud gsutil
complete $cmd -f -a '(
bash -c \'
get_completions() {
local completion COMP_CWORD COMP_LINE COMP_POINT COMP_WORDS COMPREPLY=()
# load bash-completion if necessary
declare -F _completion_loader &>/dev/null || {
source /usr/share/bash-completion/bash_completion
}
COMP_LINE=$*
COMP_POINT=${#COMP_LINE}
COMP_WORDS=("$@")
[[ ${COMP_LINE[@]: -1} = " " ]] && COMP_WORDS+=("")
COMP_CWORD=$(( ${#COMP_WORDS[@]} - 1 ))
completion=$(complete -p "$1" 2>/dev/null | awk "{print \\$(NF-1)}")
[[ -n $completion ]] || {
_completion_loader "$1"
completion=$(complete -p "$1" 2>/dev/null | awk "{print \\$(NF-1)}")
}
[[ -n $completion ]] || return 1
"$completion"
printf "%s\\n" "${COMPREPLY[@]}" | sed "s/ $//"
}
get_completions "$@"
\' -- (commandline -xpc 2>/dev/null || commandline -opc) "$(commandline -t)"
)'
end
|