Skip to content

Commit

Permalink
refactor(powerline): update for oh-my-posh V3 (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer authored Feb 23, 2021
1 parent c489882 commit 20e12c8
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions TerminalDocs/tutorials/powerline-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,11 @@ In your PowerShell profile, add the following to the end of the file:
```powershell
Import-Module posh-git
Import-Module oh-my-posh
Set-Theme Paradox
Set-PoshPrompt -Theme paradox
```

Now, each new instance starts by importing Posh-Git and Oh-My-Posh, then setting the Paradox theme from Oh-My-Posh. Oh-My-Posh comes with several [built-in themes](https://github.com/JanDeDobbeleer/oh-my-posh#themes).
Now, each new instance starts by importing Posh-Git and Oh-My-Posh, then setting the Paradox theme from Oh-My-Posh. Oh-My-Posh comes with several [built-in themes](https://ohmyposh.dev/docs/themes). If you decide to use Cascadia Code PL as a font, oh-my-posh themes that contain `minimal`
function without the need for additional icons. You can also [create a custom theme](https://ohmyposh.dev/docs/installation#change-the-theme) to match the font of your choice.

### Set Cascadia Code PL as your font

Expand All @@ -88,43 +89,44 @@ Your Windows PowerShell profile settings.json file should now look like this:
"hidden": false
},
```

> [!TIP]
> If you also use the integrated terminal in Visual Studio Code, you should add `"terminal.integrated.fontFamily": "Cascadia Code PL"` to your Visual Studio Code settings to make sure Powerline works there as well.
## Set up Powerline in WSL Ubuntu

### WSL Ubuntu prerequisites

Ubuntu has several Powerline options to install from. This tutorial will be using Go and Powerline-Go:
Ubuntu has several Powerline options to install from. This tutorial will be using oh-my-posh for Linux:

First, install oh-my-posh:

```bash
sudo apt install golang-go
go get -u github.com/justjanne/powerline-go
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-linux-amd64 -O /usr/local/bin/oh-my-posh
chmod +x /usr/local/bin/oh-my-posh
```

> [!TIP]
> If you're using Ubuntu 18.04 or 16.04, you'll need to first install the correct version of golang:
> ```bash
> sudo add-apt-repository ppa:longsleep/golang-backports
> sudo apt update
> ```
The second step is optonal. Oh-my-posh can use the same theme config regardless of the shell or evironment, so if you're already using
it on Windows Powershell for example, you can reuse that theme configuration rather than download the themes.
If you plan to use it within Ubuntu WSL only, fetch the [themes](https://ohmyposh.dev/docs/themes) so you can get started right away:

```bash
mkdir ~/.poshthemes
wget https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/themes.zip -O ~/.poshthemes/themes.zip
unzip ~/.poshthemes/themes.zip -d ~/.poshthemes
chmod u+rw ~/.poshthemes/*.json
rm ~/.poshthemes/themes.zip
```

### Customize your Ubuntu prompt

Open your `~/.bashrc` file with `nano ~/.bashrc` or the text editor of your choice. This is a bash script that runs every time bash starts. Add the following, though beware that GOPATH may already exist:
Open your `~/.bashrc` file with `nano ~/.bashrc` or the text editor of your choice. This is a bash script that runs every time bash starts. Add the following (change the theme to the one you like):

```bash
GOPATH=$HOME/go
function _update_ps1() {
PS1="$($GOPATH/bin/powerline-go -error $?)"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
eval "$(oh-my-posh --init --shell bash --config ~/.poshthemes/jandedobbeleer.omp.json)"
```

## Additional resources

* [Scott Hanselman's "How to make a pretty prompt in Windows Terminal"](https://www.hanselman.com/blog/HowToMakeAPrettyPromptInWindowsTerminalWithPowerlineNerdFontsCascadiaCodeWSLAndOhmyposh.aspx)

* [How to change/set up bash custom prompt (PS1) in Linux](https://www.cyberciti.biz/tips/howto-linux-unix-bash-shell-setup-prompt.html)
* [Oh my Posh documentation](https://ohmyposh.dev)

0 comments on commit 20e12c8

Please sign in to comment.