oh-my-posh/docs/docs/installation.mdx

395 lines
9.9 KiB
Plaintext

---
id: installation
title: Installation
sidebar_label: Installation
---
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
### 1. Setup your terminal
<Tabs
groupId="operating-systems"
defaultValue="windows"
values={[
{ label: 'windows', value: 'windows', },
{ label: 'macos', value: 'macos', },
{ label: 'unix', value: 'unix', },
]
}>
<TabItem value="windows">
#### Terminal
While Oh my Posh works on the standard terminal, we advise using the [Windows Terminal][wt].
</TabItem>
<TabItem value="macos">
#### Terminal
As the standard terminal has issues displaying the ANSI characters correctly, we advise using
[iTerm2][iterm2] or any other modern day MacOS terminal that supports ANSI characters.
</TabItem>
<TabItem value="unix">
#### Terminal
Oh my Posh uses ANSI color codes under the hood, these should work in every terminal,
but you may have to set the environment variable `$TERM` to `xterm-256color` for it to work.
</TabItem>
</Tabs>
#### Font
To see the icons displayed in Oh my Posh, **install** and **configure** your terminal to use a powerline enabled font.
The fonts we use are patched by [Nerd Fonts][nerdfonts], which offer a maximum of icons you can use.
Oh my Posh was designed using [Meslo LGM NF][meslo], but any Nerd Font should be compatible with the standard [themes][themes].
:::caution Windows fonts
Make sure to install fonts system wide to avoid seeing rectangles in your terminal. See this [thread][font-thread] for more context.
:::
### 2. Download the latest binary
<Tabs
groupId="operating-systems"
defaultValue="windows"
values={[
{ label: 'windows', value: 'windows', },
{ label: 'macos', value: 'macos', },
{ label: 'unix', value: 'unix', },
]
}>
<TabItem value="windows">
#### Scoop
A [Scoop][scoop] package is available to assist installs on Windows.
#### Manual
```powershell
mkdir C:\tools
Invoke-Webrequest https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/posh-windows-amd64.exe -OutFile C:\tools\oh-my-posh.exe
```
</TabItem>
<TabItem value="macos">
#### Homebrew
A [Homebrew][brew] package is available to assist installs on MacOS.
#### Manual
```bash
wget https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/posh-darwin-amd64 -O /usr/local/bin/oh-my-posh
chmod +x /usr/local/bin/oh-my-posh
```
</TabItem>
<TabItem value="unix">
#### Manual
```bash
wget https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
chmod +x /usr/local/bin/oh-my-posh
```
</TabItem>
</Tabs>
### 3. Download the themes
<Tabs
groupId="operating-systems"
defaultValue="windows"
values={[
{ label: 'windows', value: 'windows', },
{ label: 'macos', value: 'macos', },
{ label: 'unix', value: 'unix', },
]
}>
<TabItem value="windows">
#### Scoop
When using [Scoop][scoop], all themes are downloaded as well.
#### Manual
```powershell
mkdir ~\.poshthemes
Invoke-Webrequest https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/themes.zip -OutFile ~\.poshthemes\themes.zip
Expand-Archive ~\.poshthemes\themes.zip -DestinationPath ~\.poshthemes -Force
Remove-Item ~\.poshthemes\themes.zip
```
</TabItem>
<TabItem value="macos">
#### Homebrew
When using [Homebrew][brew], all themes are downloaded as well.
#### Manual
```bash
mkdir ~/.poshthemes
wget https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
unzip ~/.poshthemes/themes.zip -d ~/.poshthemes
chmod u+rw ~/.poshthemes/*.json
rm ~/.poshthemes/themes.zip
```
</TabItem>
<TabItem value="unix">
#### Manual
```bash
mkdir ~/.poshthemes
wget https://github.com/JanDeDobbeleer/oh-my-posh3/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
unzip ~/.poshthemes/themes.zip -d ~/.poshthemes
chmod u+rw ~/.poshthemes/*.json
rm ~/.poshthemes/themes.zip
```
</TabItem>
</Tabs>
### 4. Replace your existing prompt
If you have no idea which shell you're currently using, Oh my Posh has a utility switch that will you tell you.
```shell
oh-my-posh --print-shell
```
<Tabs
defaultValue="zsh"
values={[
{ label: 'zsh', value: 'zsh', },
{ label: 'powershell', value: 'powershell', },
{ label: 'bash', value: 'bash', },
{ label: 'nix', value: 'nix', },
{ label: 'fish', value: 'fish', },
{ label: 'nu', value: 'nu', },
]
}>
<TabItem value="powershell">
Edit `$PROFILE` in your preferred PowerShell version and add the following lines.
```powershell
[ScriptBlock]$Prompt = {
$lastCommandSuccess = $?
$realLASTEXITCODE = $global:LASTEXITCODE
$errorCode = 0
if ($lastCommandSuccess -eq $false) {
#native app exit code
if ($realLASTEXITCODE -is [int]) {
$errorCode = $realLASTEXITCODE
}
else {
$errorCode = 1
}
}
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
$startInfo.FileName = "C:\tools\oh-my-posh.exe"
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
$startInfo.Arguments = "-config=""$env:USERPROFILE\.poshthemes\jandedobbeleer.json"" -error=$errorCode -pwd=""$cleanPWD"""
$startInfo.Environment["TERM"] = "xterm-256color"
$startInfo.CreateNoWindow = $true
$startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
$startInfo.RedirectStandardOutput = $true
$startInfo.UseShellExecute = $false
if ($PWD.Provider.Name -eq 'FileSystem') {
$startInfo.WorkingDirectory = $PWD.ProviderPath
}
$process = New-Object System.Diagnostics.Process
$process.StartInfo = $startInfo
$process.Start() | Out-Null
$standardOut = $process.StandardOutput.ReadToEnd()
$process.WaitForExit()
$standardOut
$global:LASTEXITCODE = $realLASTEXITCODE
#remove temp variables
Remove-Variable realLASTEXITCODE -Confirm:$false
Remove-Variable lastCommandSuccess -Confirm:$false
}
Set-Item -Path Function:prompt -Value $Prompt -Force
```
Once added, reload your profile for the changes to take effect.
```powershell
. $profile
```
</TabItem>
<TabItem value="zsh">
Add the following to `~/.zshrc`:
```bash
function powerline_precmd() {
PS1="$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.json --error $?)"
}
function install_powerline_precmd() {
for s in "${precmd_functions[@]}"; do
if [ "$s" = "powerline_precmd" ]; then
return
fi
done
precmd_functions+=(powerline_precmd)
}
if [ "$TERM" != "linux" ]; then
install_powerline_precmd
fi
```
Once added, reload your profile for the changes to take effect.
```shell
source ~/.zshrc
```
</TabItem>
<TabItem value="bash">
Add the following to `~/.bashrc` (or `~/.profile` on MacOS):
```bash
function _update_ps1() {
PS1="$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.json -error $?)"
}
if [ "$TERM" != "linux" ] && [ -x "$(command -v oh-my-posh)" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
```
Once added, reload your profile for the changes to take effect.
```bash
. ~/.bashrc
```
Or, when using `~/.profile`.
```bash
. ~/.profile
```
</TabItem>
<TabItem value="nix">
When using `nix-shell --pure`, `oh-my-posh` will not be accessible, and
your prompt will not appear.
As a workaround you can add this snippet to `~/.bashrc`,
which should re-enable the prompt in most cases:
```bash
# Workaround for nix-shell --pure
if [ "$IN_NIX_SHELL" == "pure" ]; then
if [ -x oh-my-posh ]; then
alias powerline-go="oh-my-posh -config ~/.poshthemes/jandedobbeleer.json"
fi
fi
```
Once added, reload your profile for the changes to take effect.
```bash
. ~/.bashrc
```
</TabItem>
<TabItem value="fish">
Redefine `fish_prompt` in `~/.config/fish/config.fish`:
```bash
function fish_prompt
eval oh-my-posh -config ~/.poshthemes/jandedobbeleer.json -error $status
end
```
Once added, reload your config for the changes to take effect.
```bash
. ~/.config/fish/config.fish
```
</TabItem>
<TabItem value="nu">
Set the prompt and restart nu shell:
```bash
config set prompt "= `{{$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.json | str collect)}}`"
```
Restart nu shell for the changes to take effect.
</TabItem>
</Tabs>
### 5. Next steps
At this point you're good to go. The `jandedobbeleer.json` theme displays most common use-cases
in your prompt so 9/10 you'll be more than happy with it. However, if you want to explore additional
functionality, going through the additional steps below will help you get started.
#### Change the theme
We downloaded all the themes and set `jandedobbeleer.json` as the one to use.
However, there are a lot more to be discovered and maybe there are some you like better.
Adjust your configuration to use any other theme from the folder we created (`~/.poshthemes`).
#### Override the theme settings
Maybe there's a theme you like, but you don't fancy the colors. Or, maybe there's a segment you
want to tweak/add, or replace some of the icons with a different one. Whatever the case, read through all
available options first, by starting with the [configuration guide][configuration].
Afterwards, the easiest way to go about this is to print the current config and store it elsewhere first (for example `~/.mytheme.json`).
```bash
oh-my-posh --print-config
```
This will write the current configuration in your shell, allowing you to copy paste it in a new file
and store it somehwere. Once adjusted to your liking, [change the prompt setting][prompt] to use the newly created file.
```bash
oh-my-posh -config ~/.mytheme.json
```
🎉🎉🎉
[wt]: https://github.com/microsoft/terminal
[iterm2]: https://www.iterm2.com/
[nerdfonts]: https://www.nerdfonts.com/
[nf-cheat]: https://www.nerdfonts.com/cheat-sheet
[meslo]: https://github.com/ryanoasis/nerd-fonts/releases/download/v2.1.0/Meslo.zip
[font-thread]: https://github.com/JanDeDobbeleer/oh-my-posh3/issues/145#issuecomment-730162622
[powershell]: /docs/powershell
[themes]: https://github.com/JanDeDobbeleer/oh-my-posh3/tree/main/themes
[scoop]: /docs/scoop
[brew]: /docs/homebrew
[prompt]: /docs/installation#4-replace-your-existing-prompt
[configuration]: /docs/configure