mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 20:39:40 -08:00
467 lines
12 KiB
Plaintext
467 lines
12 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
|
|
```
|
|
|
|
#### Preview the themes
|
|
|
|
When using Scoop, replace `"~\.poshthemes\*"` with `"$(scoop prefix oh-my-posh)/themes/*"`
|
|
|
|
```powershell
|
|
Get-ChildItem -Path "~\.poshthemes\*" -Include '*.omp.json' | Sort-Object Name | ForEach-Object -Process {
|
|
$esc = [char]27
|
|
Write-Host ""
|
|
Write-Host "$esc[1m$($_.BaseName)$esc[0m"
|
|
Write-Host ""
|
|
& "C:\tools\oh-my-posh.exe" -config $($_.FullName) -pwd $PWD
|
|
Write-Host ""
|
|
}
|
|
```
|
|
|
|
</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
|
|
```
|
|
|
|
#### Preview the themes
|
|
|
|
When using Hombrew, replace `~/.poshthemes/*.omp.json` with `$(brew --prefix oh-my-posh)/themes/*.omp.json`
|
|
|
|
```bash
|
|
for file in ~/.poshthemes/*.omp.json; do echo "$file\n"; oh-my-posh --config $file --shell universal; echo "\n"; done;
|
|
```
|
|
|
|
</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
|
|
```
|
|
|
|
#### Preview the themes
|
|
|
|
```bash
|
|
for file in ~/.poshthemes/*.omp.json; do echo "$file\n"; oh-my-posh --config $file --shell universal; echo "\n"; done;
|
|
```
|
|
|
|
</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] -and $realLASTEXITCODE -gt 0) {
|
|
$errorCode = $realLASTEXITCODE
|
|
}
|
|
else {
|
|
$errorCode = 1
|
|
}
|
|
}
|
|
|
|
$executionTime = -1
|
|
$history = Get-History -ErrorAction Ignore -Count 1
|
|
if ($null -ne $history) {
|
|
$executionTime = $history.Duration.TotalMilliseconds
|
|
}
|
|
|
|
$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.omp.json"" -error=$errorCode -pwd=""$cleanPWD"" -execution-time=$executionTime"
|
|
$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 omp_preexec() {
|
|
omp_start_time=$(($(date +%s%0N)/1000000))
|
|
}
|
|
|
|
function omp_precmd() {
|
|
omp_elapsed=-1
|
|
if [ $omp_start_time ]; then
|
|
omp_now=$(($(date +%s%0N)/1000000))
|
|
omp_elapsed=$(($omp_now-$omp_start_time))
|
|
fi
|
|
PS1="$(oh-my-posh -config ~/.poshthemes/jandedobbeleer.omp.json --error $? --execution-time $omp_elapsed)"
|
|
unset omp_start_time
|
|
unset omp_now
|
|
unset omp_elapsed
|
|
}
|
|
|
|
function install_omp_hooks() {
|
|
for s in "${preexec_functions[@]}"; do
|
|
if [ "$s" = "omp_preexec" ]; then
|
|
return
|
|
fi
|
|
done
|
|
preexec_functions+=(omp_preexec)
|
|
|
|
for s in "${precmd_functions[@]}"; do
|
|
if [ "$s" = "omp_precmd" ]; then
|
|
return
|
|
fi
|
|
done
|
|
precmd_functions+=(omp_precmd)
|
|
}
|
|
|
|
if [ "$TERM" != "linux" ]; then
|
|
install_omp_hooks
|
|
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.omp.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.omp.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.omp.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.omp.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.omp.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.omp.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.omp.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.omp.json
|
|
```
|
|
|
|
#### JSON Schema
|
|
|
|
There's an easy to use [JSON schema][schema] available to validate your theme and have auto completion when editing.
|
|
When using [Visual Studio Code][vscode], you can extend your settings file (F1 -> Preferences: Open Settings (JSON))
|
|
by adding the following lines:
|
|
|
|
```json
|
|
"json.schemas": [
|
|
{
|
|
"fileMatch": ["*.omp.json"],
|
|
"url": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh3/main/themes/schema.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
|
|
[schema]: https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh3/main/themes/schema.json
|
|
[vscode]: https://code.visualstudio.com/
|