Oh-my-posh3: unix shell crash with path segment on Windows when CWD is root of drive

Created on 2 Jan 2021  Â·  15Comments  Â·  Source: JanDeDobbeleer/oh-my-posh3

Prerequisites

  • [ ] I have read and understand the CONTRIBUTING guide
  • [x ] I looked for duplicate issues before submitting this one

Description

If I use a "path" segment as in jandedobbeleer.omp.json and CD into the root of a drive, tcsh crashes.

This is because the path segment generates a "\" as the path and immediately follows it with "%{" for the next segment. However, in tcsh the resulting string is "\%" , which escapes the literal quoting of the following ANSI escape sequence, causing all kinds of havoc of unescaped characters.

I am not sure if this is restricted to tcsh, since I would expect ZSH to have the same behavior.

I can see two possible solutions:

  1. Generate "\\" instead of "\", to escape the backslash. This should work.
  2. Generate "/" instead. The Windows-native version of tcsh only uses "/" for paths, but I have no idea if that will mess up the various cygwin shells.

I can work around this for now by not using a path segment, since I prefer using tcshs "%c0n" syntax for paths in prompt anyway.

thanks!

bug windows

All 15 comments

This does not happen in zsh on macos. So we're looking at a Windows specific issue here.

@amoldeshpande can you validate if adding the following property on thepath segment resolves the issue for now?

"mapped_locations": [
    ["\\", "base"]
]

You can swap base with whatever suits you obviously.

I tried this

{
          "type": "path",
          "style": "powerline",
          "powerline_symbol": "\uE0B0",
          "foreground": "#ffffff",
          "background": "#ff479c",
          "mapped_locations" : ["\\","base"],
          "properties": {
            "prefix": " \uE5FF ",
            "style": "folder"
          }
        }

Did not help. I even tried putting the mapped_location inside properties in case that's what you meant.

As far as OS goes, since no other OS will use "\", it makes sense I only see the crash on Windows.

Regardless, generating "\" without escaping it would be problematic for any segment in any unix shell. maybe it's better to avoid it as a principle ?

@amoldeshpande you need to add it ro properties and create a double array:

{
     "type": "path",
     "style": "powerline",
     "powerline_symbol": "\uE0B0",
     "foreground": "#ffffff",
     "background": "#ff479c",
      "properties": {
            "prefix": " \uE5FF ",
            "style": "folder",
            "mapped_locations": [
                ["\\", "base"]
            ]
      }
}

tried pasting that, still crashes :(

@amoldeshpande ok, I'll try to reproduce this so I can create a proper fix.

let me know if you need a tcsh built for windows to reproduce it. I was also thinking a config property to say "convert all \ to / in paths" might be one way to avoid conflicts with other shells.

I believe a "unix in windows" switch could do the trick. As that's the context, no?

in theory yes, but it might be too broad a designation. Also, I don't regularly use cygwin -based shells so I am not sure how they'd like this to be handled. Which would be another reason for a narrowly-focused toggle.

I was also thinking a config property to say "convert all \ to / in paths" might be one way to avoid conflicts with other shells.

That's pretty much what folder_separator_icon does. In the latest builds, OMP3 will replace the OS path separator with whatever you specify in folder_separator_icon. Be that / or any other string. If you haven't tried it out, maybe give that a shot. Usage is documented here

Btw I tried to repro this by downloading the latest release of tcsh here and I was not able to reproduce any crashing. Any ideas what we might be doing differently? Here's a screenshot. And btw I don't have OMP3 set as the prompt, as I'm extremely unfamiliar with tcsh and don't know how to do that :D

image

hmm I will give folder_separator_icon a try. Meanwhile, unfortunately you have to build out of my unicode branch. I don't make releases yet for this support. I've put a compiled version here https://1drv.ms/u/s!AopJdbqzqHFho-RL1fDYFyDcfJkpqQ?e=nP1u7R if your browser will let you download an exe.

gist here https://gist.github.com/amoldeshpande/8b95c58b94fe2278b65ba10e44e5a27e describes how to set it up. except you will have to add the path segment.

I put

{
        "type": "path",
        "style": "powerline",
        "powerline_symbol": "\uE0B0",
        "foreground": "#ffffff",
        "background": "#61AFEF",
        "properties": {
          "style": "folder",
          "folder_separator_icon" : "/"
        }
      }

But the prompt is still setting a \
```
PS C:> C:\bin\posh-windows-amd64.exe --shell zsh --config C:\users\amol.poshthemes\amol.omp.json
%{%}%{%}%{%}█%{%}%{%}\%{%}%{%}█%{%}%{%}█%{%}%{%}%c03%{%}%{%}█%{%}%{%}%{%}%{%}█%{%}%{%}%T%{%}%{%}█%{%}%{%}%{%}%{%}%{%}%{%} %{%}%{%}█%{%}%{%}%{%}%{%}
PS C:>
It's a bit hard to see, but you can see the backslash a few characters after the 2nd unicode character

Edit: fix typo

Oh, I see "folder" is the one style that doesn't use folder_separator_icon

nvm. agnoster_full works. I must've mistyped something.

@TravisTX Let's add it there as well. That way it's aligned even though the only use-case is the root path.

Was this page helpful?
0 / 5 - 0 ratings