diff --git a/pkgs/development/compilers/dotnet/common.nix b/pkgs/development/compilers/dotnet/common.nix index 63b3a7de374e..e88ddfb3e37f 100644 --- a/pkgs/development/compilers/dotnet/common.nix +++ b/pkgs/development/compilers/dotnet/common.nix @@ -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 diff --git a/pkgs/development/compilers/dotnet/completions/dotnet.bash b/pkgs/development/compilers/dotnet/completions/dotnet.bash new file mode 100644 index 000000000000..56c599e4358d --- /dev/null +++ b/pkgs/development/compilers/dotnet/completions/dotnet.bash @@ -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 diff --git a/pkgs/development/compilers/dotnet/completions/dotnet.fish b/pkgs/development/compilers/dotnet/completions/dotnet.fish new file mode 100644 index 000000000000..2d5e2b5cf106 --- /dev/null +++ b/pkgs/development/compilers/dotnet/completions/dotnet.fish @@ -0,0 +1 @@ +complete -f -c dotnet -a "(dotnet complete (commandline -cp))" diff --git a/pkgs/development/compilers/dotnet/completions/dotnet.zsh b/pkgs/development/compilers/dotnet/completions/dotnet.zsh new file mode 100644 index 000000000000..0d8569b9391b --- /dev/null +++ b/pkgs/development/compilers/dotnet/completions/dotnet.zsh @@ -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