Tried to install oh-my-posh but it tells me that "the term is not recognized as..."

42.1k Views Asked by At

So I tried installing oh-my-posh for windows with

Install-Module oh-my-posh -Scope CurrentUser

and typed

Get-PoshThemes

to see the available themes which I downloaded. But I got this message

Get-PoshThemes : The term 'Get-PoshThemes' is not recognized as the name of a cmdlet, function, script file, or
operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try
again.
At line:1 char:1
+ Get-PoshThemes
+ ~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Get-PoshThemes:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Can anyone help me?

7

There are 7 best solutions below

1
On

I kept getting the cmdlet not found error even after following the guide by Robbie. For some reason a fresh install did not fix it for me but an update did:

Update-Module oh-my-posh
3
On

I following with docs from ohmyposh and it working with me

2
On

Solution

(Note: I'm running PowerShell 7.1 LTS)

First, install a Nerd Font:

[skip if you've already done so]

Instructions for installing a Nerd Font:

https://learn.microsoft.com/en-us/windows/terminal/tutorials/custom-prompt-setup#install-a-nerd-font


Then, install oh-my-posh:

1. Install: posh-git oh-my-posh:

   # This first step isn't included in the Microsoft Docs page:
   Install-Module posh-git -Scope CurrentUser
   
   # ...though this one is:
   Install-Module oh-my-posh -Scope CurrentUser

2. ...follow the rest of the instructions here:

https://github.com/JanDeDobbeleer/oh-my-posh2#installation

3. ...finally, try the command again:

   # Set the prompt theme (defaults to 'agnoster' for me)
   # ! Note: You have to do this step first (or it still won't work)
   Set-PoshPrompt

   # List the available themes (should work now)
   # ! Note: this will attempt to render a bunch of graphics in your shell
   Get-PoshThemes
   
   # ! Note: use the -List option to avoid a bunch of graphics in your shell
   # This will list the paths to the themes (in plaintext):
   Get-PoshThemes -List

Optional

To avoid manually entering Set-PoshPrompt, include the command in your PowerShell $PROFILE:

    # ...e.g. to use the included 'zash' theme:
    Set-PoshPrompt zash

...you should see your PowerShell prompt change when you open a start shell instance (i.e. new PowerShell tab or window).


Closing thoughts (side-note)

Before I got it to work, I originally followed the instructions here:

https://learn.microsoft.com/en-us/windows/terminal/tutorials/custom-prompt-setup#install-a-nerd-font

...no mention of the posh-git module or the Set-PoshPrompt command (as of 12/30/2021).

0
On

This is the workaround from the oh-my-posh faq. In this case, the profile has foreign characters in it, and utf8 characters need to be piped to invoke-expression. The oh-my-posh functions are unpacked this way. https://ohmyposh.dev/docs/faq/#powershell-the-term-oh-my-poshexe-is-not-recognized-as-a-name-of-a-cmdlet

$previousOutputEncoding = [Console]::OutputEncoding
[Console]::OutputEncoding = [Text.Encoding]::UTF8
try {
    oh-my-posh.exe init pwsh --config ~/custom.omp.json | Invoke-Expression
} finally {
    [Console]::OutputEncoding = $previousOutputEncoding
}

Error message:

# (@(& 'C:/Users/Börke/AppData/Local/Programs/oh-my-posh/bin/oh-my-posh.exe' init pwsh --config='C:\WINDOWS\system32\custom.omp.json' --print) -join "`n") | Invoke-Expression

&: The term 'C:/Users/B├╢rke/AppData/Local/Programs/oh-my-posh/bin/oh-
my-posh.exe' is not recognized as a name of a cmdlet, function, script
file, or executable program.  Check the spelling of the name, or if a
path was included, verify that the path is correct and try again.

Note that oh-my-posh is no longer installed as a powershell module, but via winget.

0
On

Form the documentation install the default theme first using:

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" | Invoke-Expression

Then you can use Get-PoshThemes

0
On

Try refreshenv. It works for me.

1
On

You can start your vs code by admin permissions and it will be fixed. I'm using oh-my-posh version 14.29.1