Change your prompt
If you have no idea which shell you're currently using, Oh My Posh has a utility switch that can tell that to you.
oh-my-posh get shell
- bash
- cmd
- elvish
- fish
- nu
- powershell
- tcsh
- xonsh
- zsh
Add the following snippet as the last line to ~/.bashrc
(could be ~/.profile
or ~/.bash_profile
depending on your environment):
eval "$(oh-my-posh init bash)"
Once added, reload your profile for the changes to take effect.
exec bash
Or, when using ~/.profile
.
. ~/.profile
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).
load(io.popen('oh-my-posh init cmd'):read("*a"))()
Once added, restart cmd for the changes to take effect.
Clink has builtin support for Oh My Posh. It allows you to set the prompt using the clink
command.
clink config prompt use oh-my-posh
To set the configuration file, use the following command:
clink set ohmyposh.theme <path>
Add the following snippet as the last line to ~/.elvish/rc.elv
:
eval (oh-my-posh init elvish)
Once added, reload your profile for the changes to take effect.
exec elvish
It is recommended to use the latest version of Fish. Versions below 3.1.2 have issues displaying the prompt.
Add the following snippet as the last line to ~/.config/fish/config.fish
:
oh-my-posh init fish | source
Once added, reload your config for the changes to take effect.
exec fish
Oh My Posh requires Nushell v0.93.0 or higher.
Add the following snippet as the last line to the Nushell env file ($nu.env-path
):
oh-my-posh init nu
This saves the initialization script to ~/.oh-my-posh.nu
.
Now, edit the Nushell config file ($nu.config-path
) and add the following line at the bottom:
source ~/.oh-my-posh.nu
If you want to save the initialization script elsewhere, you can change the first line to something like this:
oh-my-posh init nu --print | save /mylocation/myscript.nu --force
And change the source
line to:
source /mylocation/myscript.nu
Once added, restart Nushell for the changes to take effect.
Edit your PowerShell profile script, you can find its location under the $PROFILE
variable in your preferred PowerShell version. For example, using notepad:
notepad $PROFILE
When the above command gives an error, make sure to create the profile first.
New-Item -Path $PROFILE -Type File -Force
In this scenario, it can also be that PowerShell blocks running local scripts. To solve that, set PowerShell
to only require remote scripts to be signed using Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
, or sign the profile.
Add the following snippet as the last line to your PowerShell profile script:
oh-my-posh init pwsh | Invoke-Expression
If adding an exception to your Antivirus software still blocks Oh My Posh for Windows, you can try using the below alternate line in your PowerShell profile. This is a drop-in replacement to the above call with Invoke-Expression. Tested with PowerShell 7.2.4 with Bitdefender Antivirus installed and requires NO exceptions for oh-my-posh.exe. Bitdefender blocks the calls to Invoke-Expression as malicious code and this alternate line skips the double calls:
& ([ScriptBlock]::Create((oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\jandedobbeleer.omp.json" --print) -join "`n"))
Once added, reload your profile for the changes to take effect.
. $PROFILE
Add the following snippet as the last line to ~/.tcshrc
:
eval "`oh-my-posh init tcsh`"
Note that the surrounding quotes are required. Once added, reload your profile for the changes to take effect.
exec tcsh
Add the following snippet as the last line to ~/.xonshrc
:
execx($(oh-my-posh init xonsh))
Once added, reload your profile for the changes to take effect.
exec xonsh
Add the following snippet as the last line to ~/.zshrc
:
eval "$(oh-my-posh init zsh)"
As the standard terminal has issues displaying the ANSI characters correctly, you might want to skip loading just for that terminal and instead of the line above, place this in your ~/.zshrc
:
if [ "$TERM_PROGRAM" != "Apple_Terminal" ]; then
eval "$(oh-my-posh init zsh)"
fi
Note this will still load Oh My Posh for iTerm2 or any other modern day macOS terminal that supports ANSI characters.
Once added, reload your profile for the changes to take effect.
exec zsh