Skip to content

Path Segment: Add support for recursive location mapping #6166

Open
@Bertie690

Description

@Bertie690

Code of Conduct

  • I agree to follow this project's Code of Conduct

What would you like to see changed?

Rationale

I do a fair amount of work across both Windows and WSL, the latter of which treats windows files as being hosted on mounted drives (C:/ becomes /mnt/c/). Since oh-my-posh only checks mappings once in full, creating consistent location mappings for both is extremely annoying.
When accessing windows files through WSL, I effectively have to duplicate each custom mapping with the first few characters tweaked slightly, as this short snippet of my config file demonstrates:1

{
  "mapped_locations": {
    "/mnt/c": "C:/",
    "C:/Users/taylo/Documents/GitHub": "github",
    "/mnt/c/Users/taylo/Documents/GitHub": "github",
    "C:/Users/taylo/Documents": "documents-icon",
    "/mnt/c/Users/taylo/Documents": "documents-icon"
  }
} 

Notice how even though the first mapping converts /mnt/c/ into C:/, the subsequent rules still need to explicitly spell out the mounted drive path at the start for it to work.

Feature Request

To solve this, I suggest adding an additional flag to change the behavior of having multiple mapped locations in the path segment2.
With the flag enabled, rather than checking each mapping individually one by one for a match, oh-my-posh would instead attempt to sequentially and recursively apply each mapping one by one in the listed order until all had been checked3.
The above config could therefore be replicated with only 3 mappings:

{
  "mapped_locations": {
    "/mnt/c": "C:/",
    "C:/Users/taylo/Documents/GitHub": "github",
    "C:/Users/taylo/Documents": "documents-icon"
  }
} 

Notes

This would likely require changing how oh-my-posh sorts mappings (perhaps disabling it if the flag is set).

Footnotes

  1. Nerd font icons have been omitted for clarity. I do not actually spell out "documents-icon" in my path.

  2. To avoid breaking existing configs, this would naturally default to false.

  3. Similar to repeatedly calling strings.Replace.

Metadata

Metadata

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions