Skip to content

Instantly share code, notes, and snippets.

@Andrew15-5
Last active May 29, 2023 14:37
Show Gist options
  • Save Andrew15-5/f407890a21375e07361b8cfd2173f62c to your computer and use it in GitHub Desktop.
Save Andrew15-5/f407890a21375e07361b8cfd2173f62c to your computer and use it in GitHub Desktop.
bash (`dotnet`) and zsh (`_dotnet`) completion from https://docs.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete#bash
# 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
# bash parameter completion for the dotnet CLI
_dotnet_bash_complete()
{
local word=${COMP_WORDS[COMP_CWORD]}
local completions
completions="$(dotnet complete --position "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)"
if [ $? -ne 0 ]; then
completions=""
fi
COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}
complete -f -F _dotnet_bash_complete dotnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment