Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path Segment: Add support for recursive location mapping #6166

Open
1 task done
Bertie690 opened this issue Feb 15, 2025 · 0 comments
Open
1 task done

Path Segment: Add support for recursive location mapping #6166

Bertie690 opened this issue Feb 15, 2025 · 0 comments
Assignees
Labels
🤩 enhancement Improvement of a feature

Comments

@Bertie690
Copy link

Bertie690 commented Feb 15, 2025

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.

@Bertie690 Bertie690 added the 🤩 enhancement Improvement of a feature label Feb 15, 2025
@Bertie690 Bertie690 changed the title Path Segment: Add support for sequential location mapping Path Segment: Add support for recursive location mapping Feb 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤩 enhancement Improvement of a feature
Projects
None yet
Development

No branches or pull requests

2 participants