refactor(zsh): replace dotnet-suggest with in-built dotnet completion
This commit is contained in:
parent
8b13b0e70c
commit
a2f7af65e7
19
dots/.config/zsh/config/completions/completions/_dotnet
Normal file
19
dots/.config/zsh/config/completions/completions/_dotnet
Normal file
@ -0,0 +1,19 @@
|
||||
#compdef dotnet
|
||||
# zsh parameter completion for the dotnet CLI
|
||||
|
||||
_dotnet_zsh_complete()
|
||||
{
|
||||
local completions=("$(dotnet complete "$words")")
|
||||
|
||||
# If the completion list is empty, just continue with filename selection
|
||||
if [ -z "$completions" ]
|
||||
then
|
||||
_arguments '*::arguments: _normal'
|
||||
return
|
||||
fi
|
||||
|
||||
# This is not a variable assignment, don't remove spaces!
|
||||
_values = "${(ps:\n:)completions}"
|
||||
}
|
||||
|
||||
compdef _dotnet_zsh_complete dotnet
|
@ -1,38 +0,0 @@
|
||||
#compdef dotnet
|
||||
_dotnet_zsh_complete()
|
||||
{
|
||||
# debug lines, uncomment to get state variables passed to this function
|
||||
# echo "\n\n\nstate:\t'$state'"
|
||||
# echo "line:\t'$line'"
|
||||
# echo "words:\t$words"
|
||||
|
||||
# Get full path to script because dotnet-suggest needs it
|
||||
# NOTE: this requires a command registered with dotnet-suggest be
|
||||
# on the PATH
|
||||
full_path=`which ${words[1]}` # zsh arrays are 1-indexed
|
||||
# Get the full line
|
||||
# $words array when quoted like this gets expanded out into the full line
|
||||
full_line="$words"
|
||||
|
||||
# Get the completion results, will be newline-delimited
|
||||
completions=$(dotnet suggest get --executable "$full_path" -- "$full_line")
|
||||
# explode the completions by linefeed instead of by spaces into the descriptions for the
|
||||
# _values helper function.
|
||||
|
||||
exploded=(${(f)completions})
|
||||
# for later - once we have descriptions from dotnet suggest, we can stitch them
|
||||
# together like so:
|
||||
# described=()
|
||||
# for i in {1..$#exploded}; do
|
||||
# argument="${exploded[$i]}"
|
||||
# description="hello description $i"
|
||||
# entry=($argument"["$description"]")
|
||||
# described+=("$entry")
|
||||
# done
|
||||
_values 'suggestions' $exploded
|
||||
}
|
||||
|
||||
# apply this function to each command the dotnet-suggest knows about
|
||||
compdef _dotnet_zsh_complete $(dotnet-suggest list)
|
||||
|
||||
export DOTNET_SUGGEST_SCRIPT_VERSION="1.0.0"
|
Loading…
Reference in New Issue
Block a user