Skip to content

Latest commit

 

History

History
161 lines (101 loc) · 10 KB

custom-prompt-setup.md

File metadata and controls

161 lines (101 loc) · 10 KB
title description author ms.author ms.date ms.topic
Windows Terminal Custom Prompt Setup
In this tutorial, you learn how to set up Oh My Posh and Terminal-Icons in Windows Terminal.
nguyen-dows
chrnguyen
09/20/2024
tutorial

Tutorial - Set up a custom prompt for PowerShell or WSL with Oh My Posh

Oh My Posh provides theme capabilities for a fully customized command prompt experience providing Git status color-coding and prompts.

If you just want to customize the color schemes or appearance of your terminal, you can do so in the Windows Terminal settings (without the need to install Oh My Posh themes).

In this tutorial, you learn how to:

[!div class="checklist"]

Windows Terminal Custom Prompt

Install a Nerd Font

Customized command prompts often use glyphs (a graphic symbol) to style the prompt. If your font does not include the appropriate glyphs, you may see several Unicode replacement characters '▯' in your prompt.

To see all of the glyphs in your terminal, we recommend installing a Nerd Font like Cascadia Code NF, which can be downloaded from the Cascadia Code release page.

After downloading, you will need to unzip and install the font on your system. (How to add a new font to Windows).

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 select Appearance. In the Font face drop-down menu, select Cascadia Code NF or whichever Nerd Font you want to use.

Note

If you want to use a terminal font that does not support glyph icons, such as Cascadia Code PL, consider using an Oh My Posh theme that contains the minimal function, indicating that additional icons aren't required.

Customize your PowerShell prompt with Oh My Posh

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.

Install Oh My Posh for PowerShell

To customize your PowerShell prompt, install Oh My Posh using winget, which will install:

To start the installation, enter the command:

winget install JanDeDobbeleer.OhMyPosh

You will need to agree to the source terms and may run into the instance that more than one package is available. In this case, select the package ID that you want to use and re-enter the command: winget install <package ID>.

Screenshot of winget install oh my posh packages.

To use the Microsoft Store version of Oh My Posh, which will automatically update when new versions are available, use the command:

winget install XP8K0HKJFRXGCK

Enter oh-my-posh version to confirm the version number of your Oh My Posh installation. To ensure you have the latest updates, you can use the following command: winget upgrade oh-my-posh.

Note

If you want to install the newest version of Oh My Posh in PowerShell, you may want to first remove the OMP module's cached files and uninstall the old module. There are instructions on how to do this in the Oh My Posh docs. If you are more familiar with the Scoop installer or a manual installation method that allows automation, these can also be used for installing on Windows, just follow the instructions in the Oh My Posh docs.

Choose and apply a PowerShell prompt theme

You may browse the full list of themes on the Oh My Posh themes page.

Choose a theme and update your PowerShell profile with this command. (You can replace notepad with the text editor of your choice.)

notepad $PROFILE

If you receive a path error, you may not yet have a profile for PowerShell. To create one, use the following PowerShell command to create a profile and then try opening it with a text editor again.

new-item -type file -path $profile -force

Add the following to the end of your PowerShell profile file to set the paradox theme. (Replace paradox with the theme of your choice.)

oh-my-posh init pwsh --config "$env:POSH_THEMES_PATH\paradox.omp.json" | Invoke-Expression

Now, each new PowerShell instance will start by importing Oh My Posh and setting your theme.

If you receive a script error when trying to open a new PowerShell instance, your Execution Policy for PowerShell may be restricted. To set your PowerShell Execution Policy to unrestricted, you will need to launch PowerShell as an administrator and then use the following command:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

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.

Tip

See the Oh My Posh FAQs for answers to common questions or issues. To learn more about the configuration and general settings, such as how to restore the current working directory, see the Oh My Posh docs.

Customize your WSL prompt with Oh My Posh

Oh My Posh also allows you to customize WSL prompts using built-in themes.

Install Oh My Posh for WSL

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.

Customizing WSL prompts with Oh My Posh uses the Homebrew package manager for installation. When installing Homebrew for Linux, be sure to follow Next steps instructions to add Homebrew to your PATH and to your bash shell profile script.

Homebrew will install:

  • oh-my-posh - Executable, added to /usr/local/bin
  • themes - The latest Oh My Posh themes

Choose and apply a WSL prompt theme

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 view what the themes look like in the Oh My Posh Themes docs.

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:

eval "$(oh-my-posh init bash --config ~/jandedobbeleer.omp.json)"

You can replace jandedobbeleer.omp.json with the name of the theme you want to use (just make sure that it is copied in your $Home folder).

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 can customize the Oh My Posh themes if desired.

Use Terminal-Icons to add missing folder or file icons

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.

To install Terminal-Icons with PowerShell, use the command:

Install-Module -Name Terminal-Icons -Repository PSGallery

For more information, including usage and commands, see the Terminal-Icons repo on GitHub.

Additional resources