在 windows 终端内使用 git-posh or/and oh-my-posh 和命令提示符(cmd,不是 Powershell)

using git-posh or/and oh-my-posh with Command Prompt(cmd, not Powershell) inside windows terminal

最近切换到 new windows terminal,在互联网上搜索了几个小时后我找不到任何有用的东西,我想要的只是在新的 windows 终端中设置 cmd 以显示 git 分支就像 powershell 可以实现的那样。

例如这样

我对 cmd 非常满意,尤其是它能够使用额外的 linux 命令,并且不想仅仅因为 git 分支的漂亮显示而切换到 powershell。 this 是一个来源,其中对 powershell 的一切都进行了很好的解释,我只想对 CMD 做同样的事情。

提前致谢

为了使用Oh My Posh for shell-prompt customization from cmd.exe, the legacy Windows shell (citing from the docs(选项卡cmd)):

There's no out of the box support for Windows CMD when it comes to custom prompts. There is however a way to do it using Clink, which at the same time supercharges your cmd experience. Follow the installation instructions and make sure you select autostart.

正如您后来发现的那样,this issue on GitHub 提供了有关为什么无法提供本机 cmd.exe 支持(尽管 Oh My Posh 通常 shell-agnostic)以及为什么 [=41] 的背景信息=] 需要软件才能使其工作。


至于你的评论更喜欢 cmd.exe:

I have been very comfortable with cmd

从 shell 习惯迁移到新习惯无疑是一个痛苦的过渡,但在这种情况下值得考虑:

虽然并非没有它的怪癖,但 PowerShell 在几乎所有方面都远远优于 cmd.exe,并且使您能够做在 cmd.exe

中根本无法做到的事情

its ability to use additional linux commands

Linux (WSL) 从 Windows 端调用的命令都是通过 executables 调解的(特别是 wsl.exebash.exe),您同样可以从 PowerShell..

调用它