diff --git a/home/bin/custom/executable_zsh_create_completions.sh b/home/bin/custom/executable_zsh_create_completions.sh index 3baf0e43942c3bf74fa1cb45094c8929f4a5b64a..939724c1f5103c0eceeee29fb6ff0a1eea694002 100644 --- a/home/bin/custom/executable_zsh_create_completions.sh +++ b/home/bin/custom/executable_zsh_create_completions.sh @@ -7,18 +7,22 @@ set -euo pipefail +# completion dir for native #compdef completion files COMPDIR=~/.config/shell/zsh/completion +# completion dir for completion files NOT using #compdef, which need to get +# sourced +SOURCEIDR=~/.config/shell/zsh/conf.d # Bring git repos with completion files up to date -for dir in /home/varac/projects/timetracking/timewarrior-zsh-plugin ~/projects/containers/libpod; do - if [ -d "$dir" ]; then - echo "Pulling $dir..." - cd "$dir" - git pull --rebase - else - echo "$dir not found, skipping" - fi -done +# for dir in ~/projects/containers/libpod; do +# if [ -d "$dir" ]; then +# echo "Pulling $dir..." +# cd "$dir" +# git pull --rebase +# else +# echo "$dir not found, skipping" +# fi +# done # Integrated completion script output for app in cmctl; do @@ -37,4 +41,10 @@ logcli --completion-script-zsh >"$COMPDIR"/_logcli wget -q https://raw.githubusercontent.com/go-task/task/master/completion/zsh/_task -O "$COMPDIR"/_task wget -q https://raw.githubusercontent.com/ianmkenney/timewarrior_zsh_completion/main/_timew -O "$COMPDIR"/_timew -ln -s /usr/share/zsh/site-functions/tenv "$COMPDIR"/_tenv +# tenv is the only package that provides a completion file in `/usr/share/zsh/site-functions/` +# which doesn't have a underscore in front of it, so it is not sourced and needs to get fixed by prefixing a +# custom underscore +[ -L "$COMPDIR/_tenv" ] || ln -s /usr/share/zsh/site-functions/tenv "$COMPDIR"/_tenv + +# Completions that are not using #compdef, but need to get sourced +wget -q https://raw.githubusercontent.com/google-cloud-sdk-unofficial/google-cloud-sdk/739e24b483a40f1cea510459625c370c4229cce3/completion.zsh.inc -O "$SOURCEIDR"/05_completion_gcloud.sh diff --git a/home/dot_config/shell/zsh/conf.d/05_completion.sh b/home/dot_config/shell/zsh/conf.d/04_completion.sh similarity index 100% rename from home/dot_config/shell/zsh/conf.d/05_completion.sh rename to home/dot_config/shell/zsh/conf.d/04_completion.sh diff --git a/home/dot_config/shell/zsh/conf.d/05_completion_gcloud.sh b/home/dot_config/shell/zsh/conf.d/05_completion_gcloud.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7f4256a1f4dff38d63863b5807e30d9113ca5c6 --- /dev/null +++ b/home/dot_config/shell/zsh/conf.d/05_completion_gcloud.sh @@ -0,0 +1,63 @@ +autoload -U +X bashcompinit && bashcompinit +zmodload -i zsh/parameter +if ! (( $+functions[compdef] )) ; then + autoload -U +X compinit && compinit +fi + +_python_argcomplete() { + local prefix= + if [[ $COMP_LINE == 'gcloud '* ]]; then + if [[ $3 == ssh && $2 == *@* ]] ;then + # handle ssh user@instance specially + prefix=${2%@*}@ + COMP_LINE=${COMP_LINE%$2}"${2#*@}" + elif [[ $2 == *'='* ]] ; then + # handle --flag=value + prefix=${2%=*}'=' + COMP_LINE=${COMP_LINE%$2}${2/'='/' '} + fi + fi + local IFS='' + COMPREPLY=( $(IFS="$IFS" COMP_LINE="$COMP_LINE" COMP_POINT="$COMP_POINT" _ARGCOMPLETE_COMP_WORDBREAKS="$COMP_WORDBREAKS" _ARGCOMPLETE=1 "$1" 8>&1 9>&2 1>/dev/null 2>/dev/null) ) + if [[ $? != 0 ]]; then + unset COMPREPLY + return + fi + # if one completion without a trailing space, add the space + if [[ ${#COMPREPLY[@]} == 1 && $COMPREPLY != *[=' '] ]]; then + COMPREPLY+=' ' + fi + if [[ $prefix != '' ]]; then + typeset -i n + for ((n=0; n < ${#COMPREPLY[@]}; n++));do + COMPREPLY[$n]=$prefix${COMPREPLY[$n]} + done + fi +} +complete -o nospace -o default -F _python_argcomplete "gcloud" + +_completer() { + command=$1 + name=$2 + eval '[[ -n "$'"${name}"'_COMMANDS" ]] || '"${name}"'_COMMANDS="$('"${command}"')"' + set -- $COMP_LINE + shift + while [[ $1 == -* ]]; do + shift + done + [[ -n "$2" ]] && return + grep -q "${name}\s*$" <<< $COMP_LINE && + eval 'COMPREPLY=($'"${name}"'_COMMANDS)' && + return + [[ "$COMP_LINE" == *" " ]] && return + [[ -n "$1" ]] && + eval 'COMPREPLY=($(echo "$'"${name}"'_COMMANDS" | grep ^'"$1"'))' +} + +unset bq_COMMANDS +_bq_completer() { + _completer "CLOUDSDK_COMPONENT_MANAGER_DISABLE_UPDATE_CHECK=1 bq help | grep '^[^ ][^ ]* ' | sed 's/ .*//'" bq +} + +complete -o default -F _bq_completer bq +complete -o nospace -F _python_argcomplete gsutil