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-bash broken if theme file is located on a "network share" like //wsl$/ #1541

Closed tbowmo closed 2 years ago

tbowmo commented 2 years ago

Code of Conduct

What happened?

After upgrade to oh-my-posh 6.42.4 my git-bash integration stopped working. I have a common omp.json file, located inside my wsl and referenced from both powershell and git-bash, as I switch between terminals depending on which tasks I have to work on, For git bash I reference the file as //wsl$/Ubuntu-20.04/home/z6tqm/.posh/bowman.omp.json

When running oh-my-posh with this command: oh-my-posh --init --shell bash --config "//wsl$/Ubuntu-20.04/home/z6tqm/.posh/bowman.omp.json" the POSH_THEME variable is set to export POSH_THEME="\\wsl$\Ubuntu-20.04\home\z6tqm\.posh\bowman.omp.json" instead.

This results in an error when running the autogenerated script with eval: image

I tried piping the oh-my-posh autogenerated bash script to a file, changing the location for the theme:

export POSH_THEME="\\wsl$\Ubuntu-20.04\home\z6tqm\.posh\bowman.omp.json"
export POWERLINE_COMMAND="oh-my-posh"
export CONDA_PROMPT_MODIFIER=false

is changed to:

export POSH_THEME="//wsl$/Ubuntu-20.04/home/z6tqm/.posh/bowman.omp.json"
export POWERLINE_COMMAND="oh-my-posh"
export CONDA_PROMPT_MODIFIER=false

then sourcing the file in git bash:

source ./oh-my-posh-edited.sh

And hey presto, it works: image

Note that all other filepaths in the autogenerated bash script is using forward slashes, only the location of the theme is converted to use backslash instead of forward slash.

Theme

{
  "$schema": "https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/schema.json",
  "blocks": [
    {
      "type": "prompt",
      "alignment": "left",
      "segments": [
        {
          "type": "time",
          "style": "diamond",
          "leading_diamond": "",
          "foreground": "#0a2638",
          "background": "#ccd824",
          "properties": {
            "time_format": "15:04:05"
          }
        },
        {
          "type": "root",
          "style": "powerline",
          "powerline_symbol": "\uE0B0",
          "trailing_diamond": "",
          "foreground": "#ff426e",
          "background": "#440e0e",
          "properties": {
            "prefix": " ",
            "postfix": ""
          }
        },
        {
          "type": "git",
          "style": "powerline",
          "powerline_symbol": "\uE0B0",
          "foreground": "#7baeff",
          "background": "#0d3a3d",
          "background_templates": [
            "{{ if or (.Working.Changed) (.Staging.Changed) }}#f36943{{ end }}",
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#a8216b{{ end }}",
            "{{ if gt .Ahead 0 }}#35b5ff{{ end }}",
            "{{ if gt .Behind 0 }}#f89cfa{{ end }}"
          ],
          "foreground_templates": [
            "{{ if and (gt .Ahead 0) (gt .Behind 0) }}#ffffff{{ end }}"
          ],
          "properties": {
            "display_status": true,
            "display_stash_count": true,
            "display_upstream_icon": true,
            "template": "{{ .HEAD }}{{ .BranchStatus }}"
          }
        },
        {
          "type": "exit",
          "style": "diamond",
          "foreground": "#33DD2D",
          "background": "#242424",
          "trailing_diamond": "",
          "properties": {
            "display_exit_code": false,
            "always_enabled": true,
            "color_background": false,
            "error_color": "#f1184c",
            "prefix": " \ufc8d"
          }
        }
      ]
    },
    {
      "type": "prompt",
      "alignment": "right",
      "newline": false,
      "segments": [
        {
          "type": "os",
          "style": "diamond",
          "leading_diamond": "",
          "foreground": "#3A86FF",
          "background": "#242424",
          "properties": {
            "prefix": ""
          }
        },
        {
          "type": "envvar",
          "style": "plain",
          "background": "#242424",
          "foreground": "#e72552",
          "properties": {
            "var_name": "PGINSTANCE"
          }
        },
        {
          "type": "kubectl",
          "style": "diamond",
          "powerline_symbol": "\uE0B0",
          "foreground": "#ebcc34",
          "background": "#242424",
          "trailing_diamond": "",
          "properties": {
            "prefix": " \uFD31 ",
            "template": "{{.Context}}{{if .Namespace}} :: {{.Namespace}}{{end}}"
          }
        }
      ]
    },
    {
      "type": "prompt",
      "alignment": "left",
      "newline": true,
      "segments": [
        {
          "type": "path",
          "style": "plain",
          "foreground": "#33DD2D",
          "properties": {
            "prefix": " \uE5FF ",
            "style": "full",
            "folder_separator_icon": "/"
          }
        },
        {
          "type": "text",
          "style": "plain",
          "foreground": "#f1184c",
          "properties": {
            "prefix": "",
            "text": "\u279C"
          }
        }
      ]
    }
  ],
  "console_title_template": "{{.Folder}}{{if .Root}} :: root{{end}} :: {{.Shell}}"
}

What OS are you seeing the problem on?

Windows

Which shell are you using?

bash

Log output

 ~ ➜ oh-my-posh --debug --shell bash --config //wsl$/Ubuntu-20.04/home/z6tqm/.posh/bowman.omp.json

Version: 6.42.4

Segments:

ConsoleTitle(false) -   0 ms - ~ :: bash
time(true)     -   0 ms - \[\]\[\]\[\] \[\]\[\]10:12:39\[\]\[\] \[\]
root(false)    -   0 ms -
git(false)     -   1 ms -
exit(true)     -   0 ms - \[\] ﲍ\[\]\[\] \[\]\[\]\[\]
os(true)       -   0 ms - \[\]\[\]\[\]\[\]\[\] \[\]
envvar(false)  -   0 ms -
kubectl(true)  - 359 ms - \[\] ﴱ \[\]\[\]studica-adhoc2-aks :: adhoc-xprs\[\]\[\] \[\]\[\]\[\]
path(true)     -   0 ms - \[\]  \[\]\[\]~\[\]\[\] \[\]
text(true)     -   0 ms - \[\]➜\[\]\[\] \[\]

Run duration: 363.4574ms

Logs:

2022/01/06 10:12:39 debug: getenv
C:\Users\z6tqm\AppData\Local
2022/01/06 10:12:39 getenv duration: 0s, args: LOCALAPPDATA
2022/01/06 10:12:39 getCachePath duration: 539.9µs, args:
2022/01/06 10:12:39 getArgs duration: 0s, args:
2022/01/06 10:12:39 getArgs duration: 0s, args:
2022/01/06 10:12:39 getShellName duration: 0s, args:
2022/01/06 10:12:39 debug: getenv

2022/01/06 10:12:39 getenv duration: 0s, args: OMP_CACHE_DISABLED
2022/01/06 10:12:39 isRunningAsRoot duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getPathSeperator duration: 0s, args:
2022/01/06 10:12:39 getPathSeperator duration: 0s, args:
2022/01/06 10:12:39 getShellName duration: 0s, args:
2022/01/06 10:12:39 getCurrentUser duration: 0s, args:
2022/01/06 10:12:39 getHostName duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 isRunningAsRoot duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getRuntimeGOOS duration: 0s, args:
2022/01/06 10:12:39 hasCommand duration: 1.3615ms, args: git.exe
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 error: hasParentFilePath
CreateFile C:\.git: The system cannot find the file specified.
2022/01/06 10:12:39 hasParentFilePath duration: 573.7µs, args: .git
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 lastErrorCode duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getRuntimeGOOS duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 debug: getenv

2022/01/06 10:12:39 getenv duration: 0s, args: PGINSTANCE
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 hasCommand duration: 17.8135ms, args: kubectl
2022/01/06 10:12:39 debug: runCommand
apiVersion: v1
clusters:
- cluster:
    certificate-authority-data: DATA+OMITTED
    server: https://studica-ad-studica-adhoc-rg-e55a09-e6d6e197.hcp.westeurope.azmk8s.io:443
  name: studica-adhoc2-aks
contexts:
- context:
    cluster: studica-adhoc2-aks
    namespace: adhoc-xprs
    user: clusterUser_studica-adhoc-rg_studica-adhoc2-aks
  name: studica-adhoc2-aks
current-context: studica-adhoc2-aks
kind: Config
preferences: {}
users:
- name: clusterUser_studica-adhoc-rg_studica-adhoc2-aks
  user:
    client-certificate-data: REDACTED
    client-key-data: REDACTED
    token: REDACTED
2022/01/06 10:12:39 runCommand duration: 340.9936ms, args: kubectl config view --output yaml --minify
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getArgs duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getRuntimeGOOS duration: 0s, args:
2022/01/06 10:12:39 getRuntimeGOOS duration: 0s, args:
2022/01/06 10:12:39 getPathSeperator duration: 0s, args:
2022/01/06 10:12:39 getRuntimeGOOS duration: 0s, args:
2022/01/06 10:12:39 stackCount duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 isRunningAsRoot duration: 0s, args:
2022/01/06 10:12:39 getcwd duration: 0s, args:
2022/01/06 10:12:39 getPathSeperator duration: 0s, args:
2022/01/06 10:12:39 getPathSeperator duration: 0s, args:
2022/01/06 10:12:39 getShellName duration: 0s, args:
2022/01/06 10:12:39 getCurrentUser duration: 16.3µs, args:
2022/01/06 10:12:39 getHostName duration: 0s, args:
lnu commented 2 years ago

can you tell in which version it was working?

tbowmo commented 2 years ago

I came from 3.x something (been a while since I updated)..

lnu commented 2 years ago

Found it, it was working until 6.42.0 something related to this but still have to check

func (env *environment) resolveConfigPath() {
    if env.args == nil || env.args.Config == nil {
        return
    }
    configFile := *env.args.Config
    if strings.HasPrefix(configFile, "~") {
        configFile = strings.TrimPrefix(configFile, "~")
        configFile = filepath.Join(env.homeDir(), configFile)
    }
    if !filepath.IsAbs(configFile) {
        if absConfigFile, err := filepath.Abs(configFile); err == nil {
            configFile = absConfigFile
        }
    }
    *env.args.Config = filepath.Clean(configFile)
}

The last call to filepath.Clean does the replacement

lnu commented 2 years ago

I do the same as you(one single config) but I have it in windows and I use the same one everywhere(git bash, wsl, macos). That way it works all the time.

JanDeDobbeleer commented 2 years ago

@lnu that's because clean will adjust to a Windows path (as we're on Windows), I could validate if we're on Windows and bash (thus my dearest friend Cygwin) and not do it. This does mean we should really only allow full paths when using Cygwin as it will otherwise still break.

tbowmo commented 2 years ago

It's only the path to the config file that is "windowsified" ;) Paths to oh-my-posh executables are still with forward slashes, in the generated bash script.. So somehow it mixes things up?

JanDeDobbeleer commented 2 years ago

@tbowmo we added quite a bit of additional logic to support this abomination of a shell but it keeps kicking us in the back. You have to realise it's faking unix in a Windows environment and as far as executables are concerned, they're running on Windows.

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