JanDeDobbeleer / oh-my-posh

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

Path Segement not working with PSDrive Path #515

Closed Ergamon closed 3 years ago

Ergamon commented 3 years ago

Prerequisites

Description

When the current directory is a virtual path, the root is not shown in the path segment

Environment

Steps to Reproduce

Run Set-Location HKCU:\

Expected behavior: [What you expected to happen] The prompt displays a path "HKCU:"

Actual behavior: [What actually happened] The prompt dispays a path with just the folder_separator_icon

JanDeDobbeleer commented 3 years ago

@Ergamon confirmed as a bug. When adding the following it works:

{
  "type": "path",
  "style": "powerline",
  "powerline_symbol": "\uE0B0",
  "foreground": "#100e23",
  "background": "#91ddff",
  "properties": {
    "folder_icon": "\uF115",
    "folder_separator_icon": " \uE0B1 ",
    "style": "full",
    "mapped_locations": [["HKCU:", "REG"]]
  }
}

The unit tests work, but E2E with a config file it fails. Will fix.

Ergamon commented 3 years ago

Thx for your quick reply, the temporary fix with the mapped_locations works like a charm

JanDeDobbeleer commented 3 years ago

@Ergamon I believe something is off in parsing the themes for that property. When using the regular json support everything works as expected, but using jsonc something strange happens. I'll have to have a closer look but we'll fix it.

lnu commented 3 years ago

If you check the default mapped_locations, it does what it's supposed to, isn't it?

mappedLocations := map[string]string{
        "HKCU:":          pt.props.getString(WindowsRegistryIcon, "\uE0B1"),
        "HKLM:":          pt.props.getString(WindowsRegistryIcon, "\uE0B1"),
        pt.env.homeDir(): pt.props.getString(HomeIcon, "~"),
    }

It replaces HKCU: by \uE0B1

JanDeDobbeleer commented 3 years ago

@lnu it should yes, but I confirmed this isn't working when a theme is loaded.

JanDeDobbeleer commented 3 years ago

I can reproduce this when running the theme but never in a test scenario (even when loading the config EXACTLY like we do, so fully E2E). I get the feeling I'm missing something obvious (other than time).

lnu commented 3 years ago

The test is wrong. 3 locations are mapped by default like I said in my previous comment. But in the test, the WindowsRegistryIcon property is initialized like this(look at the RegistryIcon property):

cases := []struct {
        Expected      string
        HomePath      string
        Pswd          string
        Pwd           string
        PathSeperator string
        HomeIcon      string
        RegistryIcon  string
    }{
        {Expected: "~", HomeIcon: "~", HomePath: "/home/bill/", Pwd: "/home/bill/", PathSeperator: "/"},
        {Expected: "usr", HomePath: "/home/bill/", Pwd: "/usr/error/what", PathSeperator: "/"},
        {Expected: "C:", HomePath: "C:\\Users\\Bill", Pwd: "C:\\Program Files\\Go", PathSeperator: "\\"},
        {Expected: "REG", RegistryIcon: "REG", HomePath: "C:\\Users\\Bill", Pwd: "HKCU:\\Program Files\\Go", PathSeperator: "\\"},
        {Expected: "~", HomeIcon: "~", HomePath: "C:\\Users\\Bill", Pwd: "Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill", PathSeperator: "\\"},
        {Expected: "C:", HomePath: "C:\\Users\\Jack", Pwd: "Microsoft.PowerShell.Core\\FileSystem::C:\\Users\\Bill", PathSeperator: "\\"},
        {Expected: "", HomePath: "C:\\Users\\Jack", Pwd: "", PathSeperator: "\\"},
        {Expected: "DRIVE:", HomePath: "/home/bill/", Pwd: "/usr/error/what", Pswd: "DRIVE:", PathSeperator: "/"},
    }

and it overrides the default value with REG. With the following change it will work the same way as the with the profile: image

So, overriding the mapped_locations with REG like you said before is completely in line with the code. Without that, it will take the default icon which looks like a separator.

JanDeDobbeleer commented 3 years ago

Oh my god. I didn't check that default icon. I feel so stupid right now. Better call it a weekend.

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.