Merge pull request #289753 from gbtb/dotnet-shell-completions

dotnet: added shell completion scripts
This commit is contained in:
David McFarland 2024-03-30 11:32:40 -03:00 committed by GitHub
commit 79259f21ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 43 additions and 0 deletions

View File

@ -6,6 +6,7 @@
, runCommand
, expect
, curl
, installShellFiles
}: type: args: stdenv.mkDerivation (finalAttrs: args // {
doInstallCheck = true;
@ -27,6 +28,16 @@
export DOTNET_SKIP_WORKLOAD_INTEGRITY_CHECK=1 # Skip integrity check on first run, which fails due to read-only directory
'' + args.setupHook or "");
nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ installShellFiles ];
postInstall = ''
# completions snippets taken from https://learn.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete
installShellCompletion --cmd dotnet \
--bash ${./completions/dotnet.bash} \
--zsh ${./completions/dotnet.zsh} \
--fish ${./completions/dotnet.fish}
'';
} // lib.optionalAttrs (type == "sdk") {
passthru = {
tests = let

View File

@ -0,0 +1,13 @@
# bash parameter completion for the dotnet CLI
function _dotnet_bash_complete()
{
local cur="${COMP_WORDS[COMP_CWORD]}" IFS=$'\n' # On Windows you may need to use use IFS=$'\r\n'
local candidates
read -d '' -ra candidates < <(dotnet complete --position "${COMP_POINT}" "${COMP_LINE}" 2>/dev/null)
read -d '' -ra COMPREPLY < <(compgen -W "${candidates[*]:-}" -- "$cur")
}
complete -f -F _dotnet_bash_complete dotnet

View File

@ -0,0 +1 @@
complete -f -c dotnet -a "(dotnet complete (commandline -cp))"

View File

@ -0,0 +1,18 @@
# 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