oh-my-posh

Add segment in oh-my-posh if folder name contains certain letters


I want to dynamically add a segment based on the name of the current directory, here e.g., the abc.

oh-my-posh example

If the directory name is abc, then I want to add a segment showing an icon, e.g., a house, between the git information and the blue success indicator.

How can this be achieved?


Solution

  • You can make use of the text segment and the following template:

    {{ if contains .Folder \"abc\" }}icon{{ end }}

    {
      "type": "text",
      "style": "plain",
      "foreground": "#E06C75",
      "template": " {{ if contains .Folder \"abc\" }}icon{{ end }} "
    }