在PowerShell或bash中.NET Core CLI的命令行“选项卡”完成

Lots of people are using open source .NET Core and the "dotnet" command line, but few know that the .NET CLI supports command "tab" completion!

很多人正在使用开源.NET Core和“ dotnet”命令行,但很少有人知道.NET CLI支持命令“ tab”完成!

You can ensure you have it on .NET Core 2.0 with this test:

您可以通过以下测试确保在.NET Core 2.0上具有它:

C:\Users\scott>  dotnet complete "dotnet add pac"
package

You can see I do, as it proposed "package" as the completion for "pac"

您可以看到我这样做,因为它建议将“ package”作为“ pac”的完成

Now, just go into PowerShell and run:

现在,只需进入PowerShell并运行:

notepad $PROFILE

And add this code to the bottom to register "dotnet complete" as the "argument completer" for the dotnet command.

并将此代码添加到底部,以将“ dotnet complete”注册为dotnet命令的“ argument completer”。

# PowerShell parameter completion shim for the dotnet CLI 
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
    param($commandName, $wordToComplete, $cursorPosition)
        dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
           [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
        }
}

Then just use it! You can do the same not only in PowerShell, but in bash, or zsh as well!

然后就用吧! 您不仅可以在PowerShell中,而且可以在bashzsh中执行相同的操作!

It's super useful for "dotnet add package" because it'll make smart completions like this:

它对于“ dotnet添加程序包”非常有用,因为它将像这样进行智能补全:

It also works for adding/removing local project preferences as it is project file aware. Go set it up NOW, it'll take you 3 minutes.

它也可以用于添加/删除本地项目首选项,因为它可以识别项目文件。 现在就进行设置,这需要3分钟

随机但也有用:“ dotnet serve”-一个简单的命令行HTTP服务器。 (RANDOM BUT ALSO USEFUL: "dotnet serve" - A simple command-line HTTP server.)

Here's a useful little global tool - dotnet serve. It launches a server in the current working directory and serves all files in it. It's not kestrel, the .NET Application/Web Server. It's just a static webserver for development.

这是一个有用的全局小工具-dotnet服务。 它在当前工作目录中启动服务器并提供其中的所有文件。 它不是茶est,.NET应用程序/ Web服务器。 它只是用于开发的静态Web服务器。

The latest release of dotnet-serve requires the 2.1.300-preview1 .NET Core SDK or newer. Once installed, run this command:

dotnet-serve的最新版本要求使用2.1.300-preview1 .NET Core SDK或更高版本。 安装完成后,运行以下命令:

dotnet install tool --global dotnet-serve 

Then whenever I'm in a folder where I want to server something static (CSS, JS, PNGs, whatever) I can just

然后,每当我要在其中存储静态内容(CSS,JS,PNG等)的文件夹中时,我都可以

dotnet serve

It can also optionally open a web browser navigated to that localhost URL.

它还可以选择打开浏览器到该本地主机URL的Web浏览器。

NOTE: Here's a growing list of .NET Global Tools.

注意:是.NET全局工具的列表不断增加

Sponsor: Get the latest JetBrains Rider for debugging third-party .NET code, Smart Step Into, more debugger improvements, C# Interactive, new project wizard, and formatting code in columns.do

赞助商:获取最新的JetBrains Rider,用于调试第三方.NET代码,Smart Step Into,更多调试器改进,C#Interactive,新项目向导以及在column.do中格式化代码。

翻译自: https://www.hanselman.com/blog/command-line-tab-completion-for-net-core-cli-in-powershell-or-bash

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值