fix(cmd): insert executable name to avoid spaces in path

relates to #1852
This commit is contained in:
Jan De Dobbeleer 2022-03-02 08:12:57 +01:00 committed by Jan De Dobbeleer
parent d5da06e33d
commit a3a9b17f1e
2 changed files with 8 additions and 3 deletions

4
.vscode/launch.json vendored
View file

@ -59,14 +59,14 @@
] ]
}, },
{ {
"name": "Print init pwsh", "name": "Print init",
"type": "go", "type": "go",
"request": "launch", "request": "launch",
"mode": "debug", "mode": "debug",
"program": "${workspaceRoot}/src", "program": "${workspaceRoot}/src",
"args": [ "args": [
"--print-init", "--print-init",
"--shell=pwsh", "--shell=cmd",
"--config=${workspaceRoot}/themes/jandedobbeleer.omp.json" "--config=${workspaceRoot}/themes/jandedobbeleer.omp.json"
] ]
}, },

View file

@ -42,6 +42,12 @@ func getExecutablePath(env environment.Environment) (string, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
// Intermediate fix for file paths with spaces in CMD
// See https://github.com/JanDeDobbeleer/oh-my-posh/issues/1852
if *env.Args().Shell == winCMD {
fileName := environment.Base(env, executable)
return fileName, nil
}
// On Windows, it fails when the excutable is called in MSYS2 for example // On Windows, it fails when the excutable is called in MSYS2 for example
// which uses unix style paths to resolve the executable's location. // which uses unix style paths to resolve the executable's location.
// PowerShell knows how to resolve both, so we can swap this without any issue. // PowerShell knows how to resolve both, so we can swap this without any issue.
@ -51,7 +57,6 @@ func getExecutablePath(env environment.Environment) (string, error) {
executable = strings.ReplaceAll(executable, " ", "\\ ") executable = strings.ReplaceAll(executable, " ", "\\ ")
executable = strings.ReplaceAll(executable, "(", "\\(") executable = strings.ReplaceAll(executable, "(", "\\(")
executable = strings.ReplaceAll(executable, ")", "\\)") executable = strings.ReplaceAll(executable, ")", "\\)")
return executable, nil
} }
return executable, nil return executable, nil
} }