Add completion for gt and update for flux

This commit is contained in:
Pavle Portic 2022-09-20 16:23:11 +02:00
parent 30e774e554
commit 3178d29f9b
Signed by: TheEdgeOfRage
GPG Key ID: 66AD4BA646FBC0D2
2 changed files with 49 additions and 2 deletions

View File

@ -1,4 +1,4 @@
#compdef _flux flux
#compdef flux
# zsh completion for flux -*- shell-script -*-
@ -86,7 +86,24 @@ _flux()
return
fi
local activeHelpMarker="_activeHelp_ "
local endIndex=${#activeHelpMarker}
local startIndex=$((${#activeHelpMarker}+1))
local hasActiveHelp=0
while IFS='\n' read -r comp; do
# Check if this is an activeHelp statement (i.e., prefixed with $activeHelpMarker)
if [ "${comp[1,$endIndex]}" = "$activeHelpMarker" ];then
__flux_debug "ActiveHelp found: $comp"
comp="${comp[$startIndex,-1]}"
if [ -n "$comp" ]; then
compadd -x "${comp}"
__flux_debug "ActiveHelp will need delimiter"
hasActiveHelp=1
fi
continue
fi
if [ -n "$comp" ]; then
# If requested, completions are returned with a description.
# The description is preceded by a TAB character.
@ -94,7 +111,7 @@ _flux()
# We first need to escape any : as part of the completion itself.
comp=${comp//:/\\:}
local tab=$(printf '\t')
local tab="$(printf '\t')"
comp=${comp//$tab/:}
__flux_debug "Adding completion: ${comp}"
@ -103,6 +120,17 @@ _flux()
fi
done < <(printf "%s\n" "${out[@]}")
# Add a delimiter after the activeHelp statements, but only if:
# - there are completions following the activeHelp statements, or
# - file completion will be performed (so there will be choices after the activeHelp)
if [ $hasActiveHelp -eq 1 ]; then
if [ ${#completions} -ne 0 ] || [ $((directive & shellCompDirectiveNoFileComp)) -eq 0 ]; then
__flux_debug "Adding activeHelp delimiter"
compadd -x "--"
hasActiveHelp=0
fi
fi
if [ $((directive & shellCompDirectiveNoSpace)) -ne 0 ]; then
__flux_debug "Activating nospace."
noSpace="-S ''"

View File

@ -0,0 +1,19 @@
#compdef gt
###-begin-gt-completions-###
#
# yargs command completion script
#
# Installation: gt completion >> ~/.zshrc
# or gt completion >> ~/.zprofile on OSX.
#
_gt_yargs_completions()
{
local reply
local si=$IFS
IFS=$'
' reply=($(COMP_CWORD="$((CURRENT-1))" COMP_LINE="$BUFFER" COMP_POINT="$CURSOR" gt --get-yargs-completions "${words[@]}"))
IFS=$si
_describe 'values' reply
}
compdef _gt_yargs_completions gt
###-end-gt-completions-###