JanDeDobbeleer / oh-my-posh

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

Git plugin doesn't work in /mnt for WSL #2632

Closed bewing closed 2 years ago

bewing commented 2 years ago

Code of Conduct

What happened?

https://github.com/JanDeDobbeleer/oh-my-posh/blob/2ed2c038af197406f8e71fd3c8a8829d61031ec7/src/environment/shell_unix.go#L100-L102

It is common to mount arbitrary directories into /mnt. The SCM plugin (and any other code checking for WSL windows mounts) should specifically look to see if our CWD is inside a 9p type mount, and not just check the prefix of the path:

$ mount | grep 9p
tools on /init type 9p (ro,relatime,dirsync,aname=tools;fmask=022,loose,access=client,msize=65536,trans=fd,rfd=7,wfd=7)
drivers on /usr/lib/wsl/drivers type 9p (ro,nosuid,nodev,noatime,dirsync,aname=drivers;fmask=222;dmask=222,mmap,access=client,msize=65536,trans=fd,rfd=4,wfd=4)
lib on /usr/lib/wsl/lib type 9p (ro,nosuid,nodev,noatime,dirsync,aname=lib;fmask=222;dmask=222,mmap,access=client,msize=65536,trans=fd,rfd=4,wfd=4)
drvfs on /mnt/c type 9p (rw,noatime,dirsync,aname=drvfs;path=C:\;uid=1000;gid=1000;symlinkroot=/mnt/,mmap,access=client,msize=262144,trans=virtio)

Theme

    {
      "background": "#95ffa4",
      "foreground": "#193549",
      "powerline_symbol": "\ue0b0",
      "properties": {
        "fetch_status": true
      },
      "style": "powerline",
      "template": " {{ .HEAD }} {{ .BranchStatus }}{{ if .Working.Changed }} \uf044 {{ .Working.String }}{{ end }}{{ if and (.Staging.Changed) (.Working.Changed) }} |{{ end }}{{ if .Staging.Changed }} \uf046 {{ .Staging.String }}{{ end }}{{ if gt .StashCount 0}} \uf692 {{ .StashCount }}{{ end }}{{ if gt .WorktreeCount 0}} \uf1bb {{ .WorktreeCount }}{{ end }} ",
      "type": "git"
    }

What OS are you seeing the problem on?

Windows, Linux

Which shell are you using?

bash

Log output

2022/08/08 12:38:39 debug: Getenv
distro
2022/08/08 12:38:39 Getenv duration: 1.502µs, args: WSL_DISTRO_NAME
2022/08/08 12:38:39 IsWsl duration: 3.725µs, args:
2022/08/08 12:38:39 debug: Pwd
/mnt/wsl/instances/Ubuntu/home/bewing
2022/08/08 12:38:39 Pwd duration: 1.145µs, args:
2022/08/08 12:38:39 GOOS duration: 43ns, args:
2022/08/08 12:38:39 error: CommandPath
not relevant
2022/08/08 12:38:39 HasCommand duration: 363.851µs, args: git.exe
JanDeDobbeleer commented 2 years ago

@bewing this can actually be improved by only doing this for the Windows drive, no? If we rewrite strings.HasPrefix(env.Pwd(), "/mnt/") to strings.HasPrefix(env.Pwd(), "/mnt/c/") it should not result in a false positive here.

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