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

244 lines
5.9 KiB
Plaintext
Raw Normal View History

2022-03-09 02:39:31 -08:00
---
id: prompt
title: Change your prompt
sidebar_label: ✨ Prompt
---
2021-04-24 03:58:23 -07:00
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
2021-09-01 04:45:33 -07:00
:::tip
If you have no idea which shell you're currently using, Oh My Posh has a utility switch that can tell that to you.
2021-04-24 03:58:23 -07:00
:::
```bash
2022-03-19 11:32:40 -07:00
oh-my-posh get shell
2021-04-24 03:58:23 -07:00
```
<Tabs
defaultValue="powershell"
groupId="shell"
values={[
{ label: 'bash', value: 'bash', },
2023-02-18 07:46:31 -08:00
{ label: 'cmd', value: 'cmd', },
{ label: 'elvish', value: 'elvish', },
2021-04-24 03:58:23 -07:00
{ label: 'fish', value: 'fish', },
{ label: 'nu', value: 'nu', },
2023-02-18 07:46:31 -08:00
{ label: 'powershell', value: 'powershell', },
2023-02-17 01:11:44 -08:00
{ label: 'tcsh', value: 'tcsh', },
2023-02-18 07:46:31 -08:00
{ label: 'xonsh', value: 'xonsh', },
{ label: 'zsh', value: 'zsh', },
2021-04-24 03:58:23 -07:00
]
}>
2023-02-18 07:46:31 -08:00
<TabItem value="bash">
2022-05-27 16:42:03 -07:00
Add the following snippet as the last line to `~/.bashrc` (could be `~/.profile` or `~/.bash_profile` depending on your environment):
2021-04-24 03:58:23 -07:00
2023-02-18 07:46:31 -08:00
```bash
eval "$(oh-my-posh init bash)"
2021-04-24 03:58:23 -07:00
```
2022-07-29 12:36:57 -07:00
2023-02-18 07:46:31 -08:00
Once added, reload your profile for the changes to take effect.
2023-02-18 07:46:31 -08:00
```bash
exec bash
```
2021-04-24 03:58:23 -07:00
2023-02-18 07:46:31 -08:00
Or, when using `~/.profile`.
2021-04-24 03:58:23 -07:00
2023-02-18 07:46:31 -08:00
```bash
. ~/.profile
2021-04-24 03:58:23 -07:00
```
2021-11-13 04:30:41 -08:00
</TabItem>
<TabItem value="cmd">
2022-05-08 09:17:13 -07:00
There's no out-of-the-box support for Windows CMD when it comes to custom prompts.
2021-11-13 04:30:41 -08:00
There is however a way to do it using [Clink][clink], which at the same time supercharges
your cmd experience. Follow the installation instructions and make sure you select autostart.
2022-05-08 09:17:13 -07:00
Integrating Oh My Posh with Clink is easy: create a new file called oh-my-posh.lua in your Clink
2021-11-13 04:30:41 -08:00
scripts directory (run `clink info` inside cmd to find that file's location).
```lua title="oh-my-posh.lua"
2022-03-25 11:03:37 -07:00
load(io.popen('oh-my-posh init cmd'):read("*a"))()
2021-11-13 04:30:41 -08:00
```
Once added, restart cmd for the changes to take effect.
2021-04-24 03:58:23 -07:00
</TabItem>
2023-02-18 07:46:31 -08:00
<TabItem value="elvish">
2021-04-24 03:58:23 -07:00
Add the following snippet as the last line to `~/.elvish/rc.elv`:
2021-04-24 03:58:23 -07:00
```bash
2023-02-18 07:46:31 -08:00
eval (oh-my-posh init elvish)
2021-04-24 03:58:23 -07:00
```
Once added, reload your profile for the changes to take effect.
```bash
2023-02-18 07:46:31 -08:00
exec elvish
2021-04-24 03:58:23 -07:00
```
</TabItem>
<TabItem value="fish">
:::caution
2024-07-10 05:28:16 -07:00
It is recommended to use the latest version of Fish. Versions below 3.1.2 have issues displaying the prompt.
2021-04-24 03:58:23 -07:00
:::
Add the following snippet as the last line to `~/.config/fish/config.fish`:
2021-04-24 03:58:23 -07:00
```bash
2022-03-25 11:03:37 -07:00
oh-my-posh init fish | source
2021-04-24 03:58:23 -07:00
```
Once added, reload your config for the changes to take effect.
```bash
2022-03-23 11:46:55 -07:00
exec fish
2021-04-24 03:58:23 -07:00
```
</TabItem>
<TabItem value="nu">
:::caution
Oh My Posh requires Nushell v0.93.0 or higher.
2022-04-10 10:33:13 -07:00
:::
2021-04-24 03:58:23 -07:00
Add the following snippet as the last line to the Nushell env file (`$nu.env-path`):
```bash
2022-04-10 10:33:13 -07:00
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:
```bash
2022-04-10 10:33:13 -07:00
source ~/.oh-my-posh.nu
```
If you want to save the initialization script elsewhere, you can change the first line to something like this:
```bash
oh-my-posh init nu --print | save /mylocation/myscript.nu --force
```
And change the `source` line to:
```bash
2022-04-10 10:33:13 -07:00
source /mylocation/myscript.nu
```
Once added, restart Nushell for the changes to take effect.
2021-04-24 03:58:23 -07:00
2023-02-18 07:46:31 -08:00
</TabItem>
<TabItem value="powershell">
Edit your PowerShell profile script, you can find its location under the `$PROFILE` variable in your preferred PowerShell version. For example, using notepad:
```powershell
notepad $PROFILE
```
:::info
When the above command gives an error, make sure to create the profile first.
```powershell
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][sign].
2023-02-18 07:46:31 -08:00
:::
Add the following snippet as the last line to your PowerShell profile script:
2023-02-18 07:46:31 -08:00
```powershell
oh-my-posh init pwsh | Invoke-Expression
```
:::tip Antivirus software
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:
```powershell
& ([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.
```powershell
. $PROFILE
```
2023-02-17 01:11:44 -08:00
</TabItem>
<TabItem value="tcsh">
Add the following snippet as the last line to `~/.tcshrc`:
2023-02-17 01:11:44 -08:00
```bash
eval "`oh-my-posh init tcsh`"
2023-02-17 01:11:44 -08:00
```
Note that the surrounding quotes are required. Once added, reload your profile for the changes to take effect.
2023-02-17 01:11:44 -08:00
```bash
exec tcsh
```
2023-02-18 04:49:10 -08:00
</TabItem>
2023-02-18 07:46:31 -08:00
<TabItem value="xonsh">
2023-02-18 04:49:10 -08:00
Add the following snippet as the last line to `~/.xonshrc`:
2023-02-18 04:49:10 -08:00
```bash
2023-02-18 07:46:31 -08:00
execx($(oh-my-posh init xonsh))
2023-02-18 04:49:10 -08:00
```
Once added, reload your profile for the changes to take effect.
```bash
2023-02-18 07:46:31 -08:00
exec xonsh
```
</TabItem>
<TabItem value="zsh">
Add the following snippet as the last line to `~/.zshrc`:
2023-02-18 07:46:31 -08:00
```bash
eval "$(oh-my-posh init zsh)"
```
:::tip
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`:
```bash
if [ "$TERM_PROGRAM" != "Apple_Terminal" ]; then
eval "$(oh-my-posh init zsh)"
fi
```
Note this will still load Oh My Posh for [iTerm2][iterm2] or any other modern day macOS terminal that supports ANSI characters.
:::
Once added, reload your profile for the changes to take effect.
```bash
exec zsh
2023-02-18 04:49:10 -08:00
```
2021-04-24 03:58:23 -07:00
</TabItem>
</Tabs>
2021-11-13 04:30:41 -08:00
[clink]: https://chrisant996.github.io/clink/
2022-04-06 22:40:06 -07:00
[iterm2]: https://www.iterm2.com/
[homebrew-problem]: https://github.com/JanDeDobbeleer/oh-my-posh/discussions/2644
[sign]: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_signing?view=powershell-7.3#methods-of-signing-scripts