Skip to content

Commit b3f2830

Browse files
Add .NET 10+ native shell completion documentation (#49908)
* Initial plan * Add .NET 10+ native shell completion documentation Co-authored-by: meaghanlewis <[email protected]> * Fix table alignment for markdown linting Co-authored-by: meaghanlewis <[email protected]> * Add AI-usage metadata to frontmatter Co-authored-by: meaghanlewis <[email protected]> * edit pass * Clarify documentation on shell inference for tab completion * use more active verb --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: meaghanlewis <[email protected]> Co-authored-by: Meaghan Osagie <[email protected]>
1 parent f77c22b commit b3f2830

File tree

1 file changed

+106
-17
lines changed

1 file changed

+106
-17
lines changed

docs/core/tools/enable-tab-autocomplete.md

Lines changed: 106 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,106 @@
11
---
22
title: Enable tab completion
3-
description: This article teaches you how to enable tab completion for the .NET CLI for PowerShell, Bash, zsh, fish, and nushell.
3+
description: This article teaches you how to enable tab completion for the .NET CLI for PowerShell (pwsh), Bash, zsh, fish, and nushell.
44
author: adegeo
55
ms.author: adegeo
66
ms.topic: how-to
7-
ms.date: 07/06/2023
7+
ms.date: 11/14/2025
8+
ai-usage: ai-assisted
89
---
910

1011
# How to enable tab completion for the .NET CLI
1112

12-
**This article applies to:** ✔️ .NET Core 2.1 SDK and later versions
13+
**This article applies to:** ✔️ .NET 6 SDK and later versions
1314

14-
This article describes how to configure tab completion for five shells: PowerShell, Bash, zsh, fish, and nushell. For other shells, refer to their documentation on how to configure tab completion.
15+
This article describes how to configure tab completion for five shells: PowerShell (pwsh), Bash, zsh, fish, and nushell. For other shells, refer to their documentation on how to configure tab completion.
16+
17+
## Native shell completion scripts (.NET 10+)
18+
19+
Starting with .NET 10, the .NET CLI includes native shell completion scripts that run much faster than the dynamic completions available in earlier versions. Native completions generate shell-specific scripts that handle the static parts of the CLI grammar directly in the shell, providing a significant performance improvement.
20+
21+
### Generate completion scripts
22+
23+
Use the `dotnet completions generate` command to generate a completion script for your shell:
24+
25+
```console
26+
dotnet completions generate [SHELL]
27+
```
28+
29+
The `[SHELL]` parameter accepts one of the following values:
30+
31+
- `bash`
32+
- `fish`
33+
- `nushell`
34+
- `pwsh`
35+
- `zsh`
36+
37+
If you don't specify a shell, the command infers the correct shell from your environment. On Windows, it defaults to PowerShell (`pwsh`). On other systems, it checks if the file name of the `SHELL` environment variable matches any of the supported shell values.
38+
39+
### Completion capabilities
40+
41+
Native completions provide different levels of support depending on the shell:
42+
43+
| Shell | Completion type | Descriptions in tab completions |
44+
|------------|-----------------|-------------------------------------|
45+
| bash | hybrid | No |
46+
| fish | dynamic | No |
47+
| nushell | dynamic | No |
48+
| PowerShell | hybrid | Yes |
49+
| zsh | hybrid | Yes |
50+
51+
**Completion types:**
52+
53+
- **Hybrid**: Generates shell-specific code that handles static parts of the CLI grammar quickly, but falls back to the `dotnet complete` command for dynamic content (such as NuGet package IDs).
54+
- **Dynamic**: All completions go through the `dotnet complete` command, which might be slower but ensures comprehensive coverage.
55+
56+
### Configure shells to use native completions
57+
58+
Add the appropriate command to your shell's profile to enable native completions:
59+
60+
#### PowerShell
61+
62+
Add the following line to your PowerShell profile (`$PROFILE`):
63+
64+
```powershell
65+
dotnet completions generate pwsh | Out-String | Invoke-Expression
66+
```
67+
68+
#### Bash
69+
70+
Add the following line to your `.bashrc` file:
71+
72+
```bash
73+
eval "$(dotnet completions generate bash)"
74+
```
75+
76+
#### Zsh
77+
78+
Add the following line to your `.zshrc` file:
79+
80+
```zsh
81+
eval "$(dotnet completions generate zsh)"
82+
```
83+
84+
#### Fish
85+
86+
Add the following line to your `config.fish` file:
87+
88+
```fish
89+
dotnet completions generate fish | source
90+
```
91+
92+
#### Nushell
93+
94+
Add the following to the beginning of your `config.nu` file:
95+
96+
```nu
97+
dotnet completions generate nushell | save -f ~/.local/share/nushell/completions/dotnet.nu
98+
use ~/.local/share/nushell/completions/dotnet.nu *
99+
```
100+
101+
## Dynamic completion scripts (all versions)
102+
103+
For .NET versions prior to .NET 10, or if you prefer to use dynamic completions, you can configure your shell to use the `dotnet complete` command. Dynamic completions work by sending the current command line to the `dotnet complete` command and processing the results in the shell.
15104

16105
Once set up, tab completion for the .NET CLI is triggered by entering a `dotnet` command in the shell and then pressing the <kbd>Tab</kbd> key. The current command line is sent to the `dotnet complete` command, and the results are processed by the shell. You can test the results without enabling tab completion by sending something directly to the `dotnet complete` command. For example:
17106

@@ -26,19 +115,19 @@ pack
26115

27116
If that command doesn't work, make sure that .NET Core 2.0 SDK or later is installed. If it's installed but that command still doesn't work, make sure that the `dotnet` command resolves to a version of .NET Core 2.0 SDK or later. Use the `dotnet --version` command to see what version of `dotnet` your current path is resolving to. For more information, see [Select the .NET version to use](../versions/selection.md).
28117

29-
## Examples
118+
### Examples
30119

31120
Here are some examples of what tab completion provides:
32121

33-
| Input | Becomes | Because |
34-
|:----------------|:--------------------|:-----------------------------------------------|
35-
| `dotnet a⇥` | `dotnet add` | `add` is the first subcommand, alphabetically. |
36-
| `dotnet add p⇥` | `dotnet add --help` | Tab completion matches substrings, and `--help` comes first alphabetically. |
37-
| `dotnet add p⇥⇥` | `dotnet add package` | Pressing tab a second time brings up the next suggestion. |
38-
| `dotnet package add Microsoft⇥` | `dotnet package add Microsoft.ApplicationInsights.Web` | Results are returned alphabetically. |
39-
| `dotnet reference remove ⇥` | `dotnet reference remove ..\..\src\OmniSharp.DotNet\OmniSharp.DotNet.csproj` | Tab completion is project file aware. |
122+
| Input | Becomes | Because |
123+
|---------------------------------|------------------------------------------------------------------------------|------------------------------------------------------------------------------|
124+
| `dotnet a⇥` | `dotnet add` | `add` is the first subcommand, alphabetically. |
125+
| `dotnet add p⇥` | `dotnet add --help` | Tab completion matches substrings, and `--help` comes first alphabetically. |
126+
| `dotnet add p⇥⇥` | `dotnet add package` | Pressing tab a second time brings up the next suggestion. |
127+
| `dotnet package add Microsoft⇥` | `dotnet package add Microsoft.ApplicationInsights.Web` | Results are returned alphabetically. |
128+
| `dotnet reference remove ⇥` | `dotnet reference remove ..\..\src\OmniSharp.DotNet\OmniSharp.DotNet.csproj` | Tab completion is project file aware. |
40129

41-
## PowerShell
130+
### PowerShell
42131

43132
To add tab completion to **PowerShell** for the .NET CLI, create or edit the profile stored in the variable `$PROFILE`. For more information, see [How to create your profile](/powershell/module/microsoft.powershell.core/about/about_profiles#how-to-create-a-profile) and [Profiles and execution policy](/powershell/module/microsoft.powershell.core/about/about_profiles#profiles-and-execution-policy).
44133

@@ -54,7 +143,7 @@ Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
54143
}
55144
```
56145

57-
## bash
146+
### bash
58147

59148
To add tab completion to your **bash** shell for the .NET CLI, add the following code to your `.bashrc` file:
60149

@@ -74,7 +163,7 @@ function _dotnet_bash_complete()
74163
complete -f -F _dotnet_bash_complete dotnet
75164
```
76165

77-
## zsh
166+
### zsh
78167

79168
To add tab completion to your **zsh** shell for the .NET CLI, add the following code to your `.zshrc` file:
80169

@@ -99,15 +188,15 @@ _dotnet_zsh_complete()
99188
compdef _dotnet_zsh_complete dotnet
100189
```
101190

102-
## fish
191+
### fish
103192

104193
To add tab completion to your **fish** shell for the .NET CLI, add the following code to your `config.fish` file:
105194

106195
```fish
107196
complete -f -c dotnet -a "(dotnet complete (commandline -cp))"
108197
```
109198

110-
## nushell
199+
### nushell
111200

112201
To add tab completion to your **nushell** for .NET CLI, add the following to the beginning of your `config.nu` file:
113202

0 commit comments

Comments
 (0)