wsl打开函数位置_一个奇妙的邪恶联盟-带有WSL函数包装的PowerShell的真实Linux命令

wsl打开函数位置

wsl打开函数位置

Dropdown filled with shells in the Windows Terminal

I posted recently about What's the difference between a console, a terminal, and a shell? The world of Windows is interesting - and a little weird and unfamiliar to non-Windows people. You might use Ubuntu or Mac and you've picked your shell like zsh or bash or pwsh, but then you come to Windows and we're hopping between shells (and now operating systems with WSL!) on a tab by tab basis.

我最近发布了有关控制台,终端和外壳之间的区别是什么? Windows的世界很有趣-对于非Windows人士来说有点奇怪和陌生。 您可能使用Ubuntu或Mac,并且已经选择了zsh,bash或pwsh之类的shell,但随后进入Windows,我们在逐个选项卡的基础上在各个shell(以及现在带有WSL !的操作系统)之间进行切换。

If you're using a Windows shell like PowerShell because you like it's .NET Core based engine and powerful scripting language, you might still miss common *nix shell commands like ls, grep, sed and more.

如果您使用的是像PowerShell这样的Windows Shell,因为您喜欢它是基于.NET Core的引擎和强大的脚本语言,那么您可能仍会错过常见的* nix shell命令,例如ls,grep,sed等。

No matter what shell you're using in Windows (powershell, yori, cmd, whatever) you can always call into your default Ubuntu instance with "wsl command" so "wsl ls" or "wsl grep" but it'd be nice to make those more naturally and comfortably integrated.

无论您在Windows中使用哪种shell(powershell, yori ,cmd等),都可以始终使用“ wsl command”,“ wsl ls”或“ wsl grep”调用默认的Ubuntu实例,使它们更自然,更舒适地集成。

Now there's a new series of "function wrappers" that make Linux commands available directly in PowerShell so you can easily transition between multiple environments.

现在有一系列新的“函数包装器” ,它们使Linux命令可以直接在PowerShell中使用,因此您可以轻松地在多个环境之间进行转换。

This might seem weird but it allows us to create amazing piped commands that move in and out of Windows and Linux, PowerShell and bash. It's actually pretty amazing and very natural if you, like me, are non-denominational in your choice of operating system and preferred shell.

这看起来很奇怪,但是它使我们能够创建惊人的管道命令,这些命令可以移入和移出Windows和Linux,PowerShell和bash。 如果您像我一样,在选择操作系统和首选外壳程序时不是宗派的,这实际上是非常令人惊奇和自然的。

These function wrappers are very neatly designed and even expose TAB completion across operating systems! That means I can type Linux commands in PowerShell and TAB completion comes along!

这些功能包装器设计得非常整洁,甚至可以跨操作系统公开TAB完成! 这意味着我可以在PowerShell中键入Linux命令,然后TAB完成!

It's super easy to set up. From Mike Battista's Github

设置起来超级容易。 摘自Mike Battista的Github

  • Install PowerShell Core

    安装PowerShell Core

  • Install the Windows Subsystem for Linux (WSL)

    安装适用于LinuxWindows子系统(WSL)

  • Install the WslInterop module with Install-Module WslInterop

    使用Install-Module WslInterop安装WslInterop模块

  • Import commands with Import-WslCommand either from your profile for persistent access or on demand when you need a command (e.g. Import-WslCommand "awk", "emacs", "grep", "head", "less", "ls", "man", "sed", "seq", "ssh", "tail", "vim")

    使用Import-WslCommand从您的配置文件中导入命令,以进行持久访问,或者在需要命令时按需Import-WslCommand "awk", "emacs", "grep", "head", "less", "ls", "man", "sed", "seq", "ssh", "tail", "vim" (例如Import-WslCommand "awk", "emacs", "grep", "head", "less", "ls", "man", "sed", "seq", "ssh", "tail", "vim" )

You'll do your Install-Module just one, and then run notepad $profile and add just a that single last line. Make sure you change it to expose the WSL/Linux commands that you want. Once you're done, you can just open PowerShell Core and mix and match your commands!

您将只执行一个Install-Module,然后运行记事本$ profile并仅添加最后一行。 确保更改它以显示所需的WSL / Linux命令。 完成后,您只需打开PowerShell Core并混合和匹配您的命令即可!

From the blog, "With these function wrappers in place, we can now call our favorite Linux commands in a more natural way without having to prefix them with wsl or worry about how Windows paths are translated to WSL paths:"

在博客中,“有了这些功能包装器,我们现在可以更自然的方式调用我们喜欢Linux命令,而不必给它们加上wsl前缀或担心Windows路径如何转换为WSL路径:”

  • man bash

    man bash

  • less -i $profile.CurrentUserAllHosts

    less -i $profile.CurrentUserAllHosts

  • ls -Al C:\Windows\ | less

    ls -Al C:\Windows\ | less

  • grep -Ein error *.log

    grep -Ein error *.log

  • tail -f *.log

    tail -f *.log

It's a really genius thing and kudos to Mike for sharing it with us! Go try it now. https://github.com/mikebattista/PowerShell-WSL-Interop

这真是个天才,迈克也很荣幸与我们分享! 现在去尝试。 https://github.com/mikebattista/PowerShell-WSL-Interop

Sponsor: Like C#? We do too! That’s why we've developed a fast, smart, cross-platform .NET IDE which gives you even more coding power. Clever code analysis, rich code completion, instant search and navigation, an advanced debugger... With JetBrains Rider, everything you need is at your fingertips. Code C# at the speed of thought on Linux, Mac, or Windows. Try JetBrains Rider today!

发起人:喜欢C#吗? 我们也这样做! 这就是为什么我们开发了一个快速,智能,跨平台的.NET IDE的原因,它为您提供了更多的编码能力。 巧妙的代码分析,丰富的代码完成,即时搜索和导航,高级调试器...使用JetBrains Rider,您所需的一切都唾手可得。 在Linux,Mac或Windows上以思考的速度编写C#代码。 立即尝试JetBrains Rider

翻译自: https://www.hanselman.com/blog/a-wonderfully-unholy-alliance-real-linux-commands-for-powershell-with-wsl-function-wrappers

wsl打开函数位置

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值