- Включение заполнения клавишей TAB для .NET CLI How to enable TAB completion for the .NET CLI
- Примеры Examples
- PowerShell PowerShell
- bash bash
- zsh zsh
- How to enable TAB completion for the .NET CLI
- Examples
- PowerShell
- How to turn on AutoComplete in Windows Command Prompt
- Enable AutoComplete in Command Prompt
- Activate auto-complete in CMD temporarily
- Turn on auto-complete in CMD permanently
- How to force windows cmd tab complete to add a trailing slash to directory names
- 3 Answers 3
- How to use Cmd’s tab autocomplete effectively?
Включение заполнения клавишей TAB для .NET CLI How to enable TAB completion for the .NET CLI
Эта статья относится к следующему. ✔️ SDK для .NET Core 2.1 и более поздних версий This article applies to: ✔️ .NET Core 2.1 SDK and later versions
В этой статье описывается, как включить автодополнение клавишей TAB для четырех оболочек: PowerShell, Bash, zsh и fish. This article describes how to configure tab completion for four shells, PowerShell, Bash, zsh, and fish. Сведения о том, как настроить заполнение нажатием клавиши TAB в других оболочках, см. в соответствующей документации. For other shells, refer to their documentation on how to configure tab completion.
После настройки автодополнение можно активировать нажатием клавиши TAB для .NET CLI, введя в командной строке dotnet и нажав клавишу TAB. Once set up, tab completion for the .NET CLI is triggered by typing a dotnet command in the shell, and then pressing the TAB key. Текущая командная строка будет передана команде dotnet complete , а оболочка обработает результаты. The current command line is sent to the dotnet complete command, and the results are processed by your shell. Вы можете проверить результаты без активации автодополнения клавишей TAB, передав что-либо непосредственно команде dotnet complete . You can test the results without enabling tab completion by sending something directly to the dotnet complete command. Пример: For example:
Если команда не сработала, убедитесь, что установлен пакет SDK для .NET Core 2.0 или более поздней версии. If that command doesn’t work, make sure that .NET Core 2.0 SDK or above is installed. Если он установлен, но команда все равно не работает, проверьте, что команда dotnet разрешается как минимум в версию пакета SDK для .NET Core 2.0. 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 and above. Воспользуйтесь командой dotnet —version , чтобы узнать, к которой версии dotnet указывает текущий путь. Use the dotnet —version command to see what version of dotnet your current path is resolving to. Дополнительные сведения см. в статье Выбор версии .NET для использования. For more information, see Select the .NET version to use.
Примеры Examples
Ниже приведено несколько примеров возможностей, которые предоставляет автодополнение клавишей TAB: Here are some examples of what tab completion provides:
Входные данные Input | becomes becomes | because because |
---|---|---|
dotnet a⇥ | dotnet add | add является первой подкомандой в алфавитном порядке. add is the first subcommand, alphabetically. |
dotnet add p⇥ | dotnet add —help | При автодополнении клавишей TAB подстроки сопоставляются и первой по алфавиту является —help . Tab completion matches substrings and —help comes first alphabetically. |
dotnet add p⇥⇥ | dotnet add package | После второго нажатия клавиши TAB подставляется следующее предложение. Pressing tab a second time brings up the next suggestion. |
dotnet add package Microsoft⇥ | dotnet add package Microsoft.ApplicationInsights.Web | Результаты возвращаются в алфавитном порядке. Results are returned alphabetically. |
dotnet remove reference ⇥ | dotnet remove reference ..\..\src\OmniSharp.DotNet\OmniSharp.DotNet.csproj | Автодополнение клавишей TAB зависит от файла проекта. Tab completion is project file aware. |
PowerShell PowerShell
Чтобы добавить автодополнение клавишей TAB для .NET CLI в PowerShell, создайте или измените профиль, хранящийся в переменной $PROFILE . To add tab completion to PowerShell for the .NET CLI, create or edit the profile stored in the variable $PROFILE . Дополнительные сведения см. в разделах How to create your profile (Как создать свой профиль) и Profiles and execution policy (Профили и политика выполнения). For more information, see How to create your profile and Profiles and execution policy.
Добавьте в свой профиль представленный ниже код: Add the following code to your profile:
bash bash
Чтобы добавить автодополнение клавишей TAB для .NET CLI в bash, добавьте в свой файл .bashrc представленный ниже код: To add tab completion to your bash shell for the .NET CLI, add the following code to your .bashrc file:
zsh zsh
Чтобы добавить автодополнение клавишей TAB для .NET CLI в zsh, добавьте в свой файл .zshrc представленный ниже код: To add tab completion to your zsh shell for the .NET CLI, add the following code to your .zshrc file:
How to enable TAB completion for the .NET CLI
This article applies to: вњ”пёЏ .NET Core 2.1 SDK and later versions
This article describes how to configure tab completion for four shells, PowerShell, Bash, zsh, and fish. For other shells, refer to their documentation on how to configure tab completion.
Once set up, tab completion for the .NET CLI is triggered by typing a dotnet command in the shell, and then pressing the TAB key. The current command line is sent to the dotnet complete command, and the results are processed by your shell. You can test the results without enabling tab completion by sending something directly to the dotnet complete command. For example:
If that command doesn’t work, make sure that .NET Core 2.0 SDK or above 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 and above. 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.
Examples
Here are some examples of what tab completion provides:
Input | becomes | because |
---|---|---|
dotnet a⇥ | dotnet add | add is the first subcommand, alphabetically. |
dotnet add p⇥ | dotnet add —help | Tab completion matches substrings and —help comes first alphabetically. |
dotnet add p⇥⇥ | dotnet add package | Pressing tab a second time brings up the next suggestion. |
dotnet add package Microsoft⇥ | dotnet add package Microsoft.ApplicationInsights.Web | Results are returned alphabetically. |
dotnet remove reference ⇥ | dotnet remove reference ..\..\src\OmniSharp.DotNet\OmniSharp.DotNet.csproj | Tab completion is project file aware. |
PowerShell
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 and Profiles and execution policy.
Add the following code to your profile:
To add tab completion to your bash shell for the .NET CLI, add the following code to your .bashrc file:
To add tab completion to your zsh shell for the .NET CLI, add the following code to your .zshrc file:
How to turn on AutoComplete in Windows Command Prompt
If you are a Windows power user who frequently needs to use the Command Prompt regularly, then you find it useful to turn on auto-complete in Command Prompt. If you want to make the change permanent, you will have to edit the Windows Registry.
File name completion and folder name completion are quick-search features of the Windows command processor or cmd.exe. Auto-complete for CMD.exe is not enabled by default in Windows – you have to enable it.
Enable AutoComplete in Command Prompt
You can activate auto-complete permanently or for the current session only.
Activate auto-complete in CMD temporarily
To activate auto-complete in CMD for the current user for the current command session, open Run box, type the following command and hit Enter:
The /f switch enables or disables file and directory name completion characters.
Now press Ctrl+D to complete the folder name or Ctrl+F to complete a file name. Keep pressing this key combination and see the file names change.
To deactivate automatic complete, type the following and hit Enter:
Turn on auto-complete in CMD permanently
To enable auto-complete permanently in command prompt, run regedit to open the Registry Editor, and navigate to the following registry key:
You will have to edit the CompletionChar value. The default is 40 in Hexadecimal. Set the value of REG_DWORD to 9. This will enable folder name completion.
Next, double-click on PathCompletionChar and change its value to 9.
This will set the TAB key as the control character.
If you want to use the same control characters that you use for a single command session as mentioned in the first part of this post, then set the values as follows:
- 4 for Ctrl+D
- 6 for Ctrl+F
The file name auto-completion feature will work on folders too, because Windows will search for the complete path and match against both file and folder names.
How to force windows cmd tab complete to add a trailing slash to directory names
On the rare occasion that I have to use a windows command prompt rather than bash, it drives me nuts that tab completion doesn’t add a slash to the end of directory names. Is there a setting or script that I can run to force the full completion?
3 Answers 3
No there is no such setting. Your best bet is to use bash through cygwin but I expect you already knew that bit.
The answer these days is PowerShell. It is superset of the windows command line. It has many of the Linux commands. It has an object-based pipeline and has full access to the .NET framework from the command line.
And it adds a trailing slash when using tab to expand a directory name.
this is quite an old thread but I thought it might still be helpful for others.
I could not find a parameter in Windows to do the trick but I found a executable (GNU, with the Pyton source available) named PyCmd which is an improvement (according to my and my work habits) to regular CMD console.
It can be launched by double click it and it starts a regular console with cmd.exe and it loads itself in the memory to allow a lot of command line editing goodies, among them the same TAB completion behaviour I used to have under Unix Korn Shell (including the Emacs-like keys) with the trailing slashes or back-slaches for directories.
The last version is a December 2017 snapshot (but stable for me, could not meet any major trouble compared to the 2013 0.9 stable release), at: https://sourceforge.net/projects/pycmd/files/pycmd/snapshots/
You can also launch it from an existing console, from CMD.EXE and it starts a sub shell with all its editing goodies. You exit this sub-shell by exit or ^D on an empty line.
Note that I have tested it to under an alternative console like «Hyper» (MIT License, at https://hyper.is/ and https://github.com/zeit/hyper), which I prefer compared to Windows default console, and it works perfectly with it too. I think it’s fair to assume that it will work well for other consoles like ConEmu or others, but I did not test it with them.
This answer goes perhaps a little far beyond the original question but — I hope — still can provide some help to people like me who like to get the same kind of command-line behaviour as they used to have under Unix Korn shell (possibly Linux bash, I don’t know).
How to use Cmd’s tab autocomplete effectively?
I’ve used the Bash shell on Linux for years and I’m very fast with it. By frequently appealing for autocomplete by hitting the tab key, I’m able to write long commands in few keystrokes.
Recently at my job I’ve started using the Windows Command Prompt and Cmd. I’m very slow in Cmd. It has an autocomplete feature, but it works differently. I think I understand how it works, but I don’t understand how to use it effectively, in fact it often slows me down. So I ask, how to use how to use Cmd’s autocomplete effectively?
Let me give an example. First I’ll describe how I use Bash, then how I try to use Cmd, and what goes wrong.
Suppose the folders in the current directory have names made from a continent and a country, eg. africa-nigeria , asia-india , europe-france , and that I want to change folder to europe-norway .
The way Bash’s autocomplete works is that the tab key expands only if there is a unique expansion. Otherwise, nothing happens, but you can press tab a second time to list possible expansions.
So to move to Norway in Bash, I type cd and then make the following keystrokes:
- e tab for europe-
- n tab (nothing happens)
- tab again. It lists europe-netherlands and europe-norway as potential expansions.
- o tab for europe-norway .
Great! Thanks Bash.
However, when I try the same keys in Cmd, it expands e tab to europe-albania , which happens to be the first folder beginning ‘e’, but isn’t the folder I wanted! What should I do now—is it possible to make Albania into Norway? Or must I cancel the command with Escape and type everything from scratch?