LinuxCommandLibrary

oh-my-posh

Customize shell prompt appearance

TLDR

Display current shell name

$ oh-my-posh get shell
copy

Initialize for Bash
$ eval "$(oh-my-posh init bash --config [path/to/theme])"
copy

Initialize for PowerShell
$ oh-my-posh init pwsh --config [path/to/theme] | Invoke-Expression
copy

Initialize for Zsh
$ eval "$(oh-my-posh init zsh --config [path/to/theme])"
copy

Enable live reloading
$ oh-my-posh enable reload
copy

Disable live reloading
$ oh-my-posh disable reload
copy

Print debug information for troubleshooting
$ oh-my-posh debug
copy

Update to latest version
$ oh-my-posh upgrade
copy

SYNOPSIS

oh-my-posh [global-options] <command> [command-options]
oh-my-posh init <shell> [--config <theme_path>] [options]

PARAMETERS

--help, -h
    Displays help information for the main command or a specified subcommand.

--version, -v
    Displays the current version of oh-my-posh.

init <shell>
    The primary subcommand used to generate the initialization script for a specific shell (e.g., bash, zsh, fish, powershell). The output is typically piped into or sourced by the shell's profile file.

init --config <path>
    Specifies the path to the JSON theme configuration file to be used by the prompt. This is crucial for customizing the prompt's appearance and displayed segments.

init --output <path>
    Writes the generated initialization script to a specified file instead of standard output.

init --print
    Forces the output of the generated script to standard output, useful when piping the output.

init --strict
    Enables strict mode, which will cause the prompt to fail if any segment or theme configuration is invalid.

init --execution-time-threshold <ms>
    Sets the minimum execution time (in milliseconds) for the previous command to be displayed in the prompt.

config
    A subcommand providing utilities for managing themes, such as editing the current theme (config edit) or printing the current configuration (config print).

theme
    A subcommand for theme-related operations, including initializing a new theme (theme init), listing available themes (theme list), or picking a random theme (theme random).

DESCRIPTION

oh-my-posh is a powerful and highly customizable prompt engine designed to enhance the command-line experience across various shells, including Bash, Zsh, Fish, PowerShell, and Cmd. Its primary purpose is to display a rich, contextual, and aesthetically pleasing prompt that conveys essential information at a glance.

Utilizing a flexible JSON-based theme engine, oh-my-posh can show details such as Git status (branch, pending changes), current directory, Python virtual environment, Node.js version, Go version, battery status, execution time of the last command, and more. It heavily relies on Nerd Fonts to render a wide array of icons and glyphs, making the prompt visually appealing and information-dense. By generating an initialization script for your specific shell, oh-my-posh integrates seamlessly into your workflow, transforming a mundane command line into an informative dashboard.

CAVEATS

Nerd Fonts Dependency: For oh-my-posh to display icons and glyphs correctly, you must install a Nerd Font in your terminal emulator. Without it, you'll see placeholder characters or empty spaces.
Performance Overhead: While generally fast, complex themes with many segments can introduce a slight overhead to prompt rendering, potentially noticeable on slower systems or in very busy shell sessions.
Configuration Complexity: Customizing themes involves editing JSON files, which can be intricate for new users. However, a vast collection of pre-built themes is available.
Shell Profile Integration: Requires adding a line to your shell's profile file (e.g., .bashrc, .zshrc, profile.ps1) to initialize the prompt, which must be done correctly for oh-my-posh to function.

INSTALLATION

oh-my-posh can be installed using various package managers depending on your operating system:

  • Windows: winget install JanDeDobbeleer.OhMyPosh or scoop install oh-my-posh
  • macOS: brew install oh-my-posh
  • Linux: Available via apt or dnf repositories, or can be installed manually by downloading the binary.
After installation, you typically use oh-my-posh init to generate the necessary script for your shell and add it to your shell's profile file.

THEMES AND CUSTOMIZATION

oh-my-posh comes with a rich set of built-in themes that can be easily listed and previewed. Users can select a theme by specifying its path with the --config option during initialization. For advanced customization, users can create their own JSON theme files, defining segments (e.g., Git, cwd, Python) and their properties (colors, icons, visibility rules). This modular design allows for immense flexibility in tailoring the prompt to individual preferences and workflows.

NERD FONTS

The visual richness of oh-my-posh prompts, particularly the display of various icons for different programming languages, tools, and statuses, is made possible by Nerd Fonts. These are patched fonts that include a large number of glyphs from popular icon sets (e.g., Font Awesome, Material Design Icons, Devicons). Installing a Nerd Font in your terminal is a prerequisite for experiencing oh-my-posh as intended.

HISTORY

Initially conceived as a PowerShell-specific module, oh-my-posh gained significant traction among PowerShell users for its ability to create highly customized and visually rich prompts. Recognizing the demand for similar capabilities across other popular shells (Bash, Zsh, Fish), the project was re-written from scratch in Go. This strategic shift enabled cross-platform and cross-shell compatibility, significantly broadening its user base and cementing its position as a leading prompt customization tool. The Go rewrite allowed for better performance, easier distribution, and a unified experience regardless of the underlying shell or operating system.

SEE ALSO

starship(1), powerline-shell(1), bash(1), zsh(1), fish(1), pwsh(1)

Copied to clipboard