JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.01k stars 2.37k forks source link

OS segment: display WSL distro name (not OS) #443

Closed charlesroper closed 3 years ago

charlesroper commented 3 years ago

Prerequisites

Description

I run a number of WSL distros of the same type (Ubuntu 20.04 mainly) for different projects by cloning and renaming my base distro (see instructions here). It would be very useful to be able to display the WSL distro name as a segment rather than just the OS name/logo. Is this possible? Many thanks.

Environment

tradiff commented 3 years ago

@charlesroper do you know a command to get this information from within the WSL instance?

tradiff commented 3 years ago

@charlesroper sounds like this is held in the environment variable $WSL_DISTRO_NAME which you can confirm using the command echo $WSL_DISTRO_NAME

With that in mind, you should be able to display this in your prompt by adding a envvar segment to your theme. envvar docs here

charlesroper commented 3 years ago

Superb, thank you! I didn't think of using an environment var. I've customised my local copy of the negligible theme to include the distro name. Screenshot and content of theme file below.

image

{
    "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
    "blocks": [
      {
        "type": "prompt",
        "alignment": "left",
        "segments": [
          {
            "type": "os",
            "style": "plain",
            "foreground": "green",
            "properties": {
              "wsl": "",
              "wsl_separator": "",
              "prefix": "[",
              "postfix": " "
            }
          },
          {
              "type": "envvar",
              "style": "plain",
              "powerline_symbol": "\uE0B0",
              "foreground": "green",
              "properties": {
                "var_name": "WSL_DISTRO_NAME",
                "prefix": "",
                "postfix": "]"
              }
          },
          {
            "type": "path",
            "style": "plain",
            "foreground": "cyan",
            "properties": {
              "style": "full"
            }
          },
          {
            "type": "git",
            "style": "plain",
            "foreground": "lightYellow",
            "properties": {
              "prefix": ":: <lightBlue>git(</>",
              "postfix": "<lightBlue>)</>"
            }
          }
        ]
      },
      {
        "type": "prompt",
        "alignment": "right",
        "segments": [
          {
            "type": "python",
            "style": "plain",
            "foreground": "lightRed",
            "properties": {
              "display_virtual_env": true,
              "display_version": false,
              "prefix": "[ ",
              "postfix": " ]",
              "display_mode": "always"
            }
          },
          {
            "type": "time",
            "style": "plain",
            "foreground": "lightGreen"
          }
        ]
      },
      {
        "type": "newline"
      },
      {
        "type": "prompt",
        "alignment": "left",
        "segments": [
          {
            "type": "exit",
            "style": "powerline",
            "foreground": "lightGreen",
            "properties": {
              "display_exit_code": false,
              "always_enabled": true,
              "error_color": "red",
              "prefix": "\u279c"
            }
          }
        ]
      }
    ]
  }
github-actions[bot] commented 5 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.