Oh My Posh

repository·main·Indexed 12 days ago

https://github.com/jandedobbeleer/oh-my-posh

A cross-platform, shell-agnostic prompt theme engine used to create highly customized, fast, and extensible terminal prompts. Features include support for advanced layouts like transient and right prompts, an MCP (Model Context Protocol) validator for configuration files, and authentication flows for services like GitHub Copilot.

Tokens
154.3K
Snippets
533
Records
708
Agent score
97%

What's inside Oh My Posh

  1. Overview of Oh My Posh

    main

    Oh My Posh is a cross-platform, highly customizable, and extensible prompt theme engine. It is shell and platform agnostic, designed to provide a fast and highly configurable terminal prompt experience.

    Key features include:

    • Shell and platform agnostic: Works across different shells and operating systems.
    • Highly configurable: Designed to be the most configurable prompt utility available.
    • Performance: Built to be fast.
    • Advanced Prompt Layouts: Supports secondary prompts, right prompts, and transient prompts.
  2. Data collection and privacy in Oh My Posh

    main

    Oh My Posh is designed with privacy in mind. The executable itself does not use any third-party analytics or advertising frameworks. It does not log any information about the user, nor does it collect, transmit, distribute, or sell user data.

    Note that information provided to developers via installer methods is subject to the privacy policies of the specific package manager being used.

  3. Use the Aspire segment

    main

    The aspire segment displays the status of your .NET Aspire AppHost in the current repository and indicates whether it is currently running. It relies on the Aspire CLI to resolve the AppHost (via aspire extension get-apphosts) and to check for running instances (via aspire ps --format json).

    {
      "type": "aspire",
      "style": "powerline",
      "powerline_symbol": "\uE0B0",
      "foreground": "#193549",
      "background": "#ffeb3b",
      "options": {
        "fetch_running": true
      },
      "template": " \uf423 {{ .Name }}{{ if .Running }} \uf00c{{ end }} "
    }
  4. Use color templates for conditional coloring

    main

    You can define colors dynamically using an array of Go text/template strings in properties like foreground_templates or background_templates.

    Oh My Posh iterates through the array and uses the first template that returns a non-empty string. If no template returns a value, the standard foreground or background property is used as a fallback.

    Example Logic: If foreground_templates contains ['{{if .IsError}}#FF0000{{end}}', '{{if .IsSuccess}}#00FF00{{end}}'], the segment will be red if .IsError is true, green if .IsSuccess is true, or the default color otherwise.

    {
      "type": "aws",
      "style": "powerline",
      "foreground": "#ffffff",
      "background": "#111111",
      "foreground_templates": [
        "{{if contains \"default\" .Profile}}#FFA400{{end}}",
        "{{if contains \"jan\" .Profile}}#f1184c{{end}}"
      ]
    }
  5. Use the Project segment to display project versions

    main

    The project segment displays the current version of a project by detecting its configuration files (e.g., package.json, Cargo.toml, pyproject.toml). It supports a wide range of ecosystems including Node.js, Deno, JSR, Cargo, Python, Mojo, PHP, Dart, .NET, Julia, PowerShell, and Lean 4.

    Supported project files include:

    • Node.js: package.json
    • Deno: deno.json, deno.jsonc
    • JSR: jsr.json, jsr.jsonc
    • Cargo: Cargo.toml
    • Python: pyproject.toml (PEP 621 or Poetry)
    • Mojo: mojoproject.toml
    • PHP: composer.json
    • Dart: pubspec.yaml
    • Nuspec: *.nuspec (first match)
    • .NET: *.sln, *.slnf, *.slnx, *.csproj, *.vbproj, *.fsproj (resolves TargetFramework from nearest Directory.Build.props if missing)
    • Julia: JuliaProject.toml, Project.toml
    • PowerShell: *.psd1 (first match)
    • Lean 4: lakefile.lean, lakefile.toml
    {
      "type": "project",
      "style": "powerline",
      "powerline_symbol": "\uE0B0",
      "foreground": "#193549",
      "background": "#ffeb3b",
      "template": " {{ if .Error }}{{ .Error }}{{ else }}{{ if .Version }}\uf487 {{.Version}}{{ end }} {{ if .Name }}{{ .Name }}{{ end }}{{ end }} "
    }
  6. Configure Blocks in Oh My Posh

    main

    A Block is a container for one or more segments in your prompt configuration. Blocks allow you to organize segments into logical groups with specific alignments, newline behaviors, and filler characters.

    There are two primary block types:

    • prompt: Renders one or more segments.
    • rprompt: Renders segments aligned to the right of the cursor. Note: Only one rprompt block is permitted in a configuration. Supported shells include bash (with ble.sh), zsh, PowerShell, cmd, nu, and fish.
    {
      "blocks": [
        {
          "type": "prompt",
          "alignment": "left",
          "segments": []
        }
      ]
    }
  7. Choose a Path display style

    main

    The style property determines how the path is rendered. Available flavors include:

    • agnoster: Renders intermediate folders as folder_icon separated by folder_separator_icon. First and last folders are full names.
    • agnoster_full: Renders every folder name separated by folder_separator_icon.
    • agnoster_short: Renders one folder_icon followed by the last max_depth folders when the path is deep.
    • agnoster_left: Renders folders as folder_icon separated by folder_separator_icon, but only shows the first folder and its immediate child in full.
    • full: Displays the current working directory as a full string.
    • folder: Displays only the name of the current folder.
    • mixed: Similar to agnoster, but intermediate folders are shown in full if they are shorter than mixed_threshold.
    • letter: Similar to agnoster_full, but uses only the first letter of each folder (except the last folder and folders starting with symbols).
    • unique: Similar to letter, but ensures every folder name is the shortest unique value possible for the displayed path.
    • powerlevel: Similar to unique, but stops shortening once max_width is reached.
    • fish: Similar to letter, but uses dir_length for folder names, except for the last full_length_dirs folders which are shown in full.
  8. Use the Umbraco segment in Oh My Posh

    main

    The umbraco segment displays the current Umbraco version if it is detected within the current working directory. It supports both Modern Umbraco (.NET Core) and Legacy Umbraco (.NET Framework).

    Detection Logic

    • Modern Umbraco (.NET Core): Detected if the directory contains .csproj files where Umbraco is listed as a PackageReference.
    • Legacy Umbraco (.NET Framework): Detected if the directory contains a web.config file with umbraco.core.configurationstatus or umbracoConfigurationStatus in the AppSettings.

    Available Properties

    You can use the following properties within your segment template:

    • .Version (string): The detected version of Umbraco.
    • .Modern (boolean): Returns true if it is a modern Umbraco (V9+) using .NET, or false if it is legacy Umbraco using .NET Framework.
    {
      "type": "umbraco",
      "template": "{{ .Version }}"
    }
  9. Use the ZVM segment to display Zig versions

    main

    The zvm segment displays the active Zig version reported by the ZVM (Zig Version Manager).

    This segment is conditional: it only appears in your prompt when the zvm command is available in your environment and a version is currently active.

    {
      "type": "zvm",
      "style": "powerline",
      "powerline_symbol": "\uE0B0",
      "foreground": "#F7A41D",
      "background": "#193549",
      "template": " {{ if .ZigIcon }}{{ .ZigIcon }} {{ end }}{{ .Version }} ",
      "options": {
        "zigicon": "ZVM - "
      }
    }
  10. Speed up git segments with native_status

    main

    To avoid the overhead of spawning a git status subprocess (which can take up to 70% of a segment's render time on Windows), you can use the native_status option. This option reads the git index, refs, gitignore rules, and object store directly in-process, providing a significant performance boost.

    Performance Gains:

    • Windows: Up to 10x speedup (e.g., 3.4ms vs 38ms for a 1.1k file repo).
    • Linux: 2x to 4x speedup.

    Enable this within your git segment configuration to ensure the prompt remains instant even in large repositories.