Search code examples
windowspowershellcmdgit-branchwindows-terminal

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


Recently switched to new windows terminal, and after hours of searching on internet I was not able to find anything helpful, all what I want is to set up cmd inside new windows terminal to show git branches just like it's achievable for powershell.

eg like this enter image description here

I have been very comfortable with cmd especially with its ability to use additional linux commands and don't wanna switch to powershell only because of nice displays of git branches. this is a source where everything is nicely explained for powershell, all I want is to do the same for CMD.

thanks in advance


Solution

  • In order to use Oh My Posh for shell-prompt customization from cmd.exe, the legacy Windows shell (citing from the docs, tab cmd, emphasis added):

    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.

    Integrating Oh My Posh with Clink is easy: create a new file called oh-my-posh.lua in your Clink scripts directory (run clink info inside cmd to find that file's location).

    oh-my-posh.lua load(io.popen('oh-my-posh init cmd'):read("*a"))()

    Once added, restart cmd for the changes to take effect.

    As you later discovered, this issue on GitHub has background information on why native cmd.exe support isn't possible (even though Oh My Posh is generally shell-agnostic) and why third-party software is needed to make it work.


    As for your comments re preferring cmd.exe:

    I have been very comfortable with cmd

    Migrating from the shell one is used to a new one is undoubtedly a painful transition, but well worth considering in this case:

    While not without its quirks, PowerShell is vastly superior in just about every respect to cmd.exe, and enables you to do things you simply cannot do in cmd.exe

    its ability to use additional linux commands

    Linux (WSL) commands called from the Windows side are all mediated via executables (notably wsl.exe and bash.exe), which you can equally call from PowerShell.