JanDeDobbeleer / oh-my-posh

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

home_enabled not working for node in ZSH #1605

Closed ariscript closed 2 years ago

ariscript commented 2 years ago

Code of Conduct

What happened?

First off, I should probably say that this shell is not really normal. I'm running Git Bash with zsh (and oh-my-zsh) installed, with oh-my-posh to use the same prompt across shells and WSL with the same config file.

Setting home_enabled to false in my configuration is not removing my node version from my prompt when in my home directory. This same config works fine on PowerShell however (did not test on cmd). image

The node section of my config looks like this:

                {
                    "type": "node",
                    "style": "plain",
                    "foreground": "#6FBC4F",
                    "properties": {
                        "prefix": " ",
                        "home_enabled": "false",
                        "display_mode": "files",
                        "enable_version_mismatch": true,
                        "fetch_package_manager": true
                    }
                }

Theme

You can see my full config here: https://gist.github.com/dheerajpv/a8c471021e975c59f906b936b9063438

What OS are you seeing the problem on?

Windows

Which shell are you using?

zsh

Log output

Version: 7.0.0

Segments:

ConsoleTitle(true)   -   0 ms - 
session(true)        -   0 ms - ∩öê dheer on
os(true)             -   0 ms -   
path(true)           -   0 ms -  ]8;;file://C:\Users\dheer\~]8;;\ 
git(false)           -   0 ms - 
node(false)          -   0 ms - 
python(false)        -   0 ms - 
dotnet(false)        -   0 ms - 
executiontime(false) -   0 ms - 
time(true)           -   0 ms -  14:01:54 
exit(true)           -   0 ms - # 

Run duration: 1.0415ms

Cache path: C:\Users\dheer\AppData\Local/oh-my-posh

Logs:

2022/01/18 14:01:54 debug: getenv
C:\Users\dheer\AppData\Local
2022/01/18 14:01:54 getenv duration: 0s, args: LOCALAPPDATA
2022/01/18 14:01:54 getCachePath duration: 0s, args: 
2022/01/18 14:01:54 getArgs duration: 0s, args: 
2022/01/18 14:01:54 getArgs duration: 0s, args: 
2022/01/18 14:01:54 getShellName duration: 515.3┬╡s, args: 
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/01/18 14:01:54 isRunningAsRoot duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getPathSeperator duration: 0s, args: 
2022/01/18 14:01:54 getPathSeperator duration: 0s, args: 
2022/01/18 14:01:54 getShellName duration: 0s, args: 
2022/01/18 14:01:54 getCurrentUser duration: 0s, args: 
2022/01/18 14:01:54 getHostName duration: 0s, args: 
2022/01/18 14:01:54 lastErrorCode duration: 0s, args: 
2022/01/18 14:01:54 environ duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: SSH_CONNECTION
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: SSH_CLIENT
2022/01/18 14:01:54 getCurrentUser duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: POSH_SESSION_DEFAULT_USER
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getArgs duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 getPathSeperator duration: 0s, args: 
2022/01/18 14:01:54 getArgs duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 getPathSeperator duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 isWsl duration: 0s, args: 
2022/01/18 14:01:54 stackCount duration: 0s, args: 
2022/01/18 14:01:54 isRunningAsRoot duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getPathSeperator duration: 0s, args: 
2022/01/18 14:01:54 getPathSeperator duration: 0s, args: 
2022/01/18 14:01:54 getShellName duration: 0s, args: 
2022/01/18 14:01:54 getCurrentUser duration: 0s, args: 
2022/01/18 14:01:54 getHostName duration: 0s, args: 
2022/01/18 14:01:54 lastErrorCode duration: 0s, args: 
2022/01/18 14:01:54 environ duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getRuntimeGOOS duration: 0s, args: 
2022/01/18 14:01:54 hasCommand duration: 525.2┬╡s, args: git.exe
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 error: hasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2022/01/18 14:01:54 hasParentFilePath duration: 0s, args: .git
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: VIRTUAL_ENV
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: CONDA_ENV_PATH
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: CONDA_DEFAULT_ENV
2022/01/18 14:01:54 debug: getenv

2022/01/18 14:01:54 getenv duration: 0s, args: PYENV_VERSION
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 executionTime duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 getcwd duration: 0s, args: 
2022/01/18 14:01:54 lastErrorCode duration: 0s, args: 
2022/01/18 14:01:54 debug: getenv
C:\Users\dheer\AppData\Local
2022/01/18 14:01:54 getenv duration: 0s, args: LOCALAPPDATA
2022/01/18 14:01:54 getCachePath duration: 0s, args:
JanDeDobbeleer commented 2 years ago

@dheerajpv try setting it to a boolean instead of a string:

"home_enabled": false,
ariscript commented 2 years ago

That didn't fix it. It still does the same thing.

JanDeDobbeleer commented 2 years ago

@dheerajpv works on my machine is zsh, how do you init oh-my-posh?

ariscript commented 2 years ago

I followed the docs and added eval "$(oh-my-posh --init --shell zsh --config ~/.poshtheme.omp.json)" to my .zshrc.

JanDeDobbeleer commented 2 years ago

@dheerajpv we actually do the following to get the home folder:

home := os.Getenv("HOME")
if len(home) > 0 {
    return home
}

This should return the right path, just like in your screenshot. That would imply the we do not get the right path back (or in the same format) when calling getcwd. Try the following in your shell BUT that could break other things as git bash is simply a disaster to work with:

eval "$(oh-my-posh --init --shell zsh --config ~/.poshtheme.oh-my-posh.json --pwd=$PWD)"
ariscript commented 2 years ago

Still didn't seem to fix the issue. It's doing the same thing as before.

Probably should've mentioned this before, but whatever you were doing in v2 for this seemed to work perfectly well on git bash.

JanDeDobbeleer commented 2 years ago

V2 didn't work in git bash so that can't be true 😁 we did changes to transform the path to the right in underneath git bash because of other reasons which might (once again) introduce other issues. I'll log the result as well so we can see what's going on.

JanDeDobbeleer commented 2 years ago

@dheerajpv the latest release added additional debug information for these parts specifically.

ariscript commented 2 years ago

This is what the latest release logs when I debug:

Version: 7.5.1

Segments:

ConsoleTitle(true)   -   0 ms -
session(true)        -   0 ms - %{%} %{%}%{%}dheer%{%}%{%} on%{%}
os(true)             -   0 ms - %{%} %{%}%{%}%{%}%{%} %{%}
path(true)           -   0 ms - %{%} %{%}%{%}%{%}~%{%}%{%}%{%} %{%}
git(false)           -   0 ms -
node(false)          -   0 ms -
python(false)        -   0 ms -
dotnet(false)        -   0 ms -
executiontime(false) -   0 ms -
time(true)           -   0 ms - %{%} %{%}%{%}15:42:53%{%}%{%} %{%}
exit(true)           -   0 ms - %{%}#%{%}%{%} %{%}

Run duration: 1.5907ms

Cache path: C:\Users\dheer\AppData\Local/oh-my-posh

Logs:

2022/01/20 15:42:53 getArgs duration: 0s, args:
2022/01/20 15:42:53 getArgs duration: 0s, args:
2022/01/20 15:42:53 getShellName duration: 0s, args:
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/01/20 15:42:53 isRunningAsRoot duration: 0s, args:
2022/01/20 15:42:53 getShellName duration: 0s, args:
2022/01/20 15:42:53 lastErrorCode duration: 0s, args:
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 536µs, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 getPathSeperator duration: 0s, args:
2022/01/20 15:42:53 getPathSeperator duration: 0s, args:
2022/01/20 15:42:53 getCurrentUser duration: 0s, args:
2022/01/20 15:42:53 getHostName duration: 0s, args:
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 templateCache duration: 536µs, args:
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: SSH_CONNECTION
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: SSH_CLIENT
2022/01/20 15:42:53 getCurrentUser duration: 0s, args:
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: POSH_SESSION_DEFAULT_USER
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 getArgs duration: 0s, args:
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 getPathSeperator duration: 0s, args:
2022/01/20 15:42:53 getArgs duration: 0s, args:
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 getPathSeperator duration: 0s, args:
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 isWsl duration: 0s, args:
2022/01/20 15:42:53 stackCount duration: 0s, args:
2022/01/20 15:42:53 templateCache duration: 0s, args:
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 getRuntimeGOOS duration: 0s, args:
2022/01/20 15:42:53 hasCommand duration: 529.6µs, args: git.exe
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 error: hasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2022/01/20 15:42:53 hasParentFilePath duration: 0s, args: .git
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: VIRTUAL_ENV
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: CONDA_ENV_PATH
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: CONDA_DEFAULT_ENV
2022/01/20 15:42:53 debug: getenv

2022/01/20 15:42:53 getenv duration: 0s, args: PYENV_VERSION
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 executionTime duration: 0s, args:
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 debug: pwd
C:\Users\dheer
2022/01/20 15:42:53 pwd duration: 0s, args:
2022/01/20 15:42:53 debug: homeDir
C:\Users\dheer
2022/01/20 15:42:53 lastErrorCode duration: 0s, args:
2022/01/20 15:42:53 debug: getenv
C:\Users\dheer\AppData\Local
2022/01/20 15:42:53 getenv duration: 0s, args: LOCALAPPDATA
2022/01/20 15:42:53 getCachePath duration: 0s, args:
JanDeDobbeleer commented 2 years ago

Now it gets really interesting. I'll have a look tomorrow.

JanDeDobbeleer commented 2 years ago

@dheerajpv but wait, node is disabled here. That's what you expect, right?

ariscript commented 2 years ago

It says that node is disabled, but it does still appear in my prompt (not any of the others though for some reason). image

Now that I look at it, it also shows that node is disabled in the first comment too...

JanDeDobbeleer commented 2 years ago

@dheerajpv are you certain the config file you use on debug is identical to the one you use for initialization?

ariscript commented 2 years ago

Yes, I'm using the same config for both cases: image

Also, it works as intended in powershell so it shouldn't be a configuration issue.

ariscript commented 2 years ago

Any update on this?

JanDeDobbeleer commented 2 years ago

@dheerajpv didn't find time yet.

JanDeDobbeleer commented 2 years ago

I just spent the past hour installing and configuring a setup which is identical to yours and I can't reproduce this at all. Both git bash and zsh work as expected, it also doesn't make sense that you can see it in you prompt but debug says otherwise (that's technically NOT possible without a different config or oh-my-posh version for prompt/debug).

BTW, I really urge you to use a different shell. This is by far the worst experience I've ever seen. That zsh shell has all sorts of quirks.

JanDeDobbeleer commented 2 years ago

Found a way to reproduce it! Now let's see if we can fix it :-)

ariscript commented 2 years ago

works now, thanks!

github-actions[bot] commented 6 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.