0

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?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
user69453
  • 1,279
  • 1
  • 17
  • 43

1 Answers1

1

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 }} "
}

Jan De Dobbeleer
  • 566
  • 4
  • 12
  • Thanks, but this does somehow not work; If I remove the ``if``, I get to see the 'icon' when I cd into ``abc``. But when I add the ``if`` condition, it is no longer displayed, altought I am still in ``abc``. – user69453 Jul 30 '22 at 09:00
  • OK, it works when I use ``"template": " {{ if contains .Folder \"abc\" }}icon{{ end }} "`` – user69453 Jul 30 '22 at 09:02
  • @user69453 also correct, I'll adjust my answer! – Jan De Dobbeleer Aug 03 '22 at 07:14