Skip to content

Commit

Permalink
Main > Live (#468)
Browse files Browse the repository at this point in the history
* Update dynamic-profiles.md (#438)

* Update dynamic-profiles.md

Create section for dynamic profile for `Developer Powershell for VS 2019`

* Update dynamic-profiles.md

Update name and remove `startingDirectory`

* Update dynamic-profiles.md

Explain a little better

* Update VS version info in 3rd party (#462)

* Update custom prompt tutorial w latest OMP steps (#467)

* Add themes link

Co-authored-by: Shubham Gogna <36936863+shgogna@users.noreply.github.com>
  • Loading branch information
mattwojo and shgogna authored Dec 22, 2021
1 parent a86679a commit 34ae89e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 84 deletions.
Binary file added TerminalDocs/images/ohmyposh-terminal-prompt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
158 changes: 74 additions & 84 deletions TerminalDocs/tutorials/custom-prompt-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,148 +3,138 @@ title: Windows Terminal Custom Prompt Setup
description: In this tutorial, you learn how to set up Oh My Posh and Terminal-Icons in Windows Terminal.
author: cinnamon-msft
ms.author: cinnamon
ms.date: 10/08/2021
ms.date: 12/20/2021
ms.topic: tutorial
#Customer intent: As a developer or IT admin, I want to set up a customized command line experience using Oh My Posh, Terminal-Icons, and posh-git in my Windows Terminal.
---

# Tutorial: Set up a custom prompt in Windows Terminal using Oh My Posh, Terminal-Icons, and Posh Git
# Tutorial: Set up a custom prompt for PowerShell or WSL with Oh My Posh

[Oh My Posh](https://ohmyposh.dev) provides theme capabilities for a customized command prompt experience providing Git status color-coding and prompts. [Terminal-Icons](https://github.com/devblackops/Terminal-Icons) adds file and folder icons when displaying items in the terminal.

![Windows Terminal Custom Prompt](./../images/custom-prompt.png)
This tutorial provides some resources and direction to help you customize your command prompt for PowerShell or Windows Subsystem for Linux (WSL) using [Oh My Posh](https://ohmyposh.dev). Oh My Posh provides theme capabilities for a fully customized command prompt experience providing Git status color-coding and prompts.

In this tutorial, you learn how to:

> [!div class="checklist"]
>
> * Set up Oh My Posh in PowerShell
> * Set up Oh My Posh in Ubuntu/WSL
> * Set up Terminal-Icons in PowerShell
> * Add missing glyphs
> * [Install a Nerd Font](#install-a-nerd-font)
> * [Customize your PowerShell prompt with Oh My Posh](#customize-your-powershell-prompt-with-oh-my-posh)
> * [Customize your WSL prompt with Oh My Posh](#customize-your-wsl-prompt-with-oh-my-posh)
> * [Use Terminal-Icons to add missing folder or file icons](#use-terminal-icons-to-add-missing-folder-or-file-icons)
![Windows Terminal Custom Prompt](./../images/custom-prompt.png)

## Install a Nerd Font

Oh My Posh and Terminal-Icons use glyphs in order to style the prompt. If your font does not include the appropriate glyphs, you may see several Unicode replacement characters '&#x25AF;' throughout your prompt. In order to see all of the glyphs in your terminal, you should install a [Nerd Font](https://nerdfonts.com). (If you'd like a font that looks like Cascadia Code, the Caskaydia Cove Nerd Font was built from the Cascadia Code repository by a community member.)
Customized command prompts often use glyphs (a graphic symbol) in order to style the prompt. If your font does not include the appropriate glyphs, you may see several Unicode replacement characters '&#x25AF;' throughout your prompt. In order to see all of the glyphs in your terminal, we recommend installing a [Nerd Font](https://www.nerdfonts.com/font-downloads).

If you'd like a font that looks like Cascadia Code, the Caskaydia Cove Nerd Font was built from the Cascadia Code repository by a community member.)

After downloading, you will need to unzip and install the font on your system. ([How to add a new font to Windows](https://support.microsoft.com/en-us/office/add-a-font-b7c5f17c-4426-4b53-967f-455339c564c1)).

### Install Oh My Posh
To set a Nerd Font for use with Oh My Posh and Terminal Icons, open the Windows Terminal settings UI by selecting **Settings** (Ctrl+,) from your Windows Terminal dropdown menu. Select the profile where you wish to apply the font, PowerShell for example, and then the **Appearance** tab. In the **Font face** drop-down menu, select *CaskaydiaCove Nerd Font* or whichever Nerd font you would like to use with your customized prompt.

Oh My Posh enables you to use a full color set to define and render your terminal prompt, including the ability to use built-in themes or create your own custom theme.
> [!NOTE]
> If you want to use a terminal font that does not support glyph icons, such as [Cascadia Code PL](https://github.com/microsoft/cascadia-code/releases), you may consider using an Oh My Posh theme that contains the `minimal` function, indicating that additional icons aren't required.
### Install for PowerShell only
## Customize your PowerShell prompt with Oh My Posh

If you are only interested in using Oh My Posh with PowerShell, you can follow these installation instructions. If you want to use Oh My Posh for adding themes to both PowerShell and WSL command lines, skip down to the winget installation instructions below.
Oh My Posh enables you to use a full color set to define and render your terminal prompt, including the ability to use built-in themes or create your own custom theme.

1. Using PowerShell, install Oh My Posh with the command:
If you want to use the same custom prompt themes across both PowerShell and WSL, we recommend installing Oh My Posh using [winget](/package-manager/winget/), the official Windows Package Manager. It's included with Windows 11, but you may need to install it if you're running Windows 10. Then follow the `winget` install instructions in the [Oh My Posh docs](https://ohmyposh.dev/docs/windows).

```powershell
Install-Module oh-my-posh -Scope CurrentUser
```
### Install Oh My Posh for PowerShell

2. Browse the prompt themes, with the command:
To customize your PowerShell prompt, you can install Oh My Posh using the [PowerShell install-module](/powershell/module/powershellget/install-module). Enter the command:

```powershell
Get-PoshThemes
```
```powershell
Install-Module oh-my-posh -Scope CurrentUser
```

3. Choose a theme and update your PowerShell profile with this command. (You can replace `notepad` with the text editor of your choice.)
This will install:

```powershell
notepad $PROFILE
```
- `oh-my-posh.exe`: The Windows executable
- `themes`: The latest [Oh My Posh themes](https://ohmyposh.dev/docs/themes)

4. Add the following to the end of your PowerShell profile file to set the `paradox` theme. (Replace `paradox` with the theme of your choice.)
You may also want to enter this command to ensure you have the latest updates: `Update-Module oh-my-posh`.

```powershell
Import-Module oh-my-posh
Set-PoshPrompt -Theme paradox
```
> [!NOTE]
> If you are more familiar with the [Scoop](https://scoop.sh/) installer or [Chocolatey](https://chocolatey.org/) package manager, these can also be used for installing on Windows, just follow the instructions in the [Oh My Posh docs](https://ohmyposh.dev/docs/windows).
Now, each new PowerShell instance will start by importing Oh My Posh and setting your command line theme.
### Choose and apply a PowerShell prompt theme

> [!NOTE]
> This is not your Windows Terminal profile. Your PowerShell profile is a script that runs every time PowerShell starts. [Learn more about PowerShell profiles](/powershell/module/microsoft.powershell.core/about/about_profiles).
To browse the Oh My Posh prompt themes, use the command:

### Install for PowerShell or WSL using Winget
```powershell
Get-PoshThemes
```

If you would like to use Oh My Posh to style both Windows and Windows Subsystem for Linux (WSL) command lines, we recommend using the [Windows Package Manager](/windows/package-manager). You can [install winget](https://github.com/microsoft/winget-cli#installing-the-client), the package manager client, using the App Installer from the Microsoft Store. (This may require an Insiders build if you're running Windows 10.)
Choose a theme and update your PowerShell profile with this command. (You can replace `notepad` with the text editor of your choice.)

1. Using PowerShell, install Oh My Posh using winget with the command:
```powershell
notepad $PROFILE
```

```powershell
winget install JanDeDobbeleer.OhMyPosh
```
Add the following to the end of your PowerShell profile file to set the `paradox` theme. (Replace `paradox` with the theme of your choice.)

This will install:
* oh-my-posh.exe - Windows executable, added to your $PATH.
* oh-my-posh-wsl - Linux executable, added to your $PATH for use in the WSL.
* themes - The latest Oh My Posh themes.
```powershell
Import-Module oh-my-posh
Set-PoshPrompt -Theme paradox
```

2. Using PowerShell, browse the prompt themes by entering:
Now, each new PowerShell instance will start by importing Oh My Posh and setting your command line theme.

```powershell
Get-ChildItem -Path "~\AppData\Local\Programs\oh-my-posh\themes\*" -Include '*.omp.json' | Sort-Object Name | ForEach-Object -Process {
$esc = [char]27
Write-Host ""
Write-Host "$esc[1m$($_.BaseName)$esc[0m"
Write-Host ""
oh-my-posh --config $($_.FullName) --pwd $PWD
Write-Host ""
}
```
> [!NOTE]
> This is not your Windows Terminal profile. Your PowerShell profile is a script that runs every time PowerShell starts. [Learn more about PowerShell profiles](/powershell/module/microsoft.powershell.core/about/about_profiles).
You can also browse the [prompt themes in the Oh My Posh docs](https://ohmyposh.dev/docs/themes).
## Customize your WSL prompt with Oh My Posh

3. Choose a theme and update your PowerShell `$PROFILE` file and WSL distribution `.bashrc` file.
Oh My Posh now allows you to customize WSL prompts, just like you would a PowerShell prompt using [built-in themes](https://ohmyposh.dev/docs/themes).

For PowerShell, open your profile file with `notepad $PROFILE` and add the following:
### Install Oh My Posh for WSL

```powershell
oh-my-posh --init --shell pwsh --config ~/AppData/Local/Programs/oh-my-posh/themes/jandedobbeleer.omp.json | Invoke-Expression
```
We recommend installing Oh My Posh for WSL, whether using Bash, Zsh, or something else, by following the [Linux install guide in the Oh My Posh docs](https://ohmyposh.dev/docs/linux).

Once added, reload your profile for the changes to take effect.
Currently the recommended path for customizing WSL prompts with Oh My Posh uses the [Homebrew package manager](https://brew.sh/) for installation. (Homebrew works with WSL now!) When installing Homebrew for Linux, be sure to follow [Next steps](https://docs.brew.sh/Homebrew-on-Linux#install) instructions to add Homebrew to your PATH and to your bash shell profile script.

4. For your WSL distribution, open your profile file with `nano .bashrc` and add the following. (Replacing `paradox.omp.json` with the theme of your choice. You can view the list in the `.poshthemes` folder that was added to your distributions directory.)
Homebrew will install:

```bash
eval "$(oh-my-posh-wsl --init --shell bash --config ~/.poshthemes/paradox.omp.json)"
```
- `oh-my-posh` - Executable, added to /usr/local/bin
- `themes` - The latest Oh My Posh themes

Learn more by visiting the [Oh My Posh documentation](https://ohmyposh.dev/docs/windows).
### Choose and apply a WSL prompt theme

## Set your font in Windows Terminal settings
The Oh My Posh themes will be found in the oh-my-posh directory as JSON files. You can find it by entering `cd $(brew --prefix oh-my-posh)`, then just `cd themes` and `ls` for the list. For Ubuntu-20.04 running via WSL, the path is likely to be something like: `\\wsl.localhost\Ubuntu-20.04\home\linuxbrew\.linuxbrew\Cellar\oh-my-posh\6.34.1\themes`. You can also view what the themes look like in the Oh My Posh docs: [Themes](https://ohmyposh.dev/docs/themes).

To set a Nerd Font for use with Oh My Posh and Terminal Icons, open the Windows Terminal settings UI by selecting **Settings** (Ctrl+,) from your Windows Terminal dropdown menu. Select the Windows PowerShell profile, and then the **Appearance** tab. In the **Font face** drop-down menu, select *CaskaydiaCove Nerd Font* or whichever Nerd font you would like to use with your customized prompt.
To use a theme, copy it from the `themes` folder to your `$Home` folder, then add this line to the bottom of the `.profile` file found in your `$Home` folder:

<!-- ![Windows Terminal Settings UI Font face menu](../../images/settings-powershell-font.png) -->
```bash
eval "$(oh-my-posh --init --shell bash --config ~/jandedobbeleer.omp.json)"
```

> [!NOTE]
> If you decide to use [Cascadia Code PL](https://github.com/microsoft/cascadia-code/releases) as your terminal font, you may consider using an Oh My Posh theme that contains the `minimal` function, indicating that additional icons aren't required.
You can replace `jandedobbeleer.omp.json` with the name of whichever theme you prefer to use as long as it's copied to your `$Home` folder.

## Set up posh-git in PowerShell
Alternatively, if you are using oh-my-posh in both Windows with PowerShell and with WSL, you can share your PowerShell theme with WSL by pointing to a theme in your Windows user's home folder. In your WSL distribution's `.profile` path, replace ~ with the path: `/mnt/c/Users/<WINDOWSUSERNAME>`. Replacing `<WINDOWSUSERNAME>` with your own Windows username. You may also need to add `$env:POSH_PATH` to your $PATH if you have only installed the Oh My Posh executable for PowerShell.

Posh-git adds a Git status summary to your Windows Terminal prompt with information and tab completion for Git commands, parameters, remotes and branch names.
<!-- To reference the theme directly from it's original folder rather than moving it to $Home, you can use:
eval "$(oh-my-posh --init --shell bash --config $(brew --prefix oh-my-posh)/themes/jandedobbeleer.omp.json)" -->

1. Install posh-git using PowerShell with the command:
You can [customize the Oh My Posh themes](https://ohmyposh.dev/docs/linux#customize) if desired.

```powershell
Install-Module posh-git -Scope CurrentUser
```
## Use Terminal-Icons to add missing folder or file icons

2. Update your PowerShell profile file: `notepad $PROFILE`. (You can replace nodepad with the text editor of your choice).
[Terminal-Icons](https://github.com/devblackops/Terminal-Icons) is a PowerShell module that adds file and folder icons that may be missing when displaying files or folders in Windows Terminal, looking up their appropriate icon based on name or extension. It attempts to use icons for well-known files/folders, but falls back to a generic file or folder icon if one is not found.

In your PowerShell profile, add the following to the end of the file:
To install Terminal-Icons with PowerShell, use the command:

```powershell
Import-Module posh-git
```
```powershell
PS> Install-Module -Name Terminal-Icons -Repository PSGallery
```

Your PowerShell command prompt will now display a status whenever you are inside of a Git directory. Learn more in the [posh-git repo on GitHub](https://github.com/dahlbyk/posh-git#using-posh-git).
For more information, including usage and commands, see the [Terminal-Icons](https://github.com/devblackops/Terminal-Icons) repo on GitHub.

## Additional resources

* [Oh my Posh documentation](https://ohmyposh.dev)
* [Terminal-Icons Repository](https://github.com/devblackops/Terminal-Icons)
* [Posh-Git documentation](https://github.com/dahlbyk/posh-git#overview): Posh-Git is a PowerShell module that integrates Git and PowerShell by providing Git status summary information that can be displayed in the PowerShell prompt.
* [PowerLine documentation](https://powerline.readthedocs.io/en/master/overview.html): Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome, i3 and Qtile.

0 comments on commit 34ae89e

Please sign in to comment.