From a3a9b17f1eaf18b83b49348acf3956d6db99806c Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 2 Mar 2022 08:12:57 +0100 Subject: [PATCH] fix(cmd): insert executable name to avoid spaces in path relates to #1852 --- .vscode/launch.json | 4 ++-- src/engine/init.go | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 1aaa837a..f1355e6b 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -59,14 +59,14 @@ ] }, { - "name": "Print init pwsh", + "name": "Print init", "type": "go", "request": "launch", "mode": "debug", "program": "${workspaceRoot}/src", "args": [ "--print-init", - "--shell=pwsh", + "--shell=cmd", "--config=${workspaceRoot}/themes/jandedobbeleer.omp.json" ] }, diff --git a/src/engine/init.go b/src/engine/init.go index 29cdc692..a199e6e0 100644 --- a/src/engine/init.go +++ b/src/engine/init.go @@ -42,6 +42,12 @@ func getExecutablePath(env environment.Environment) (string, error) { if err != nil { 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 // 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. @@ -51,7 +57,6 @@ func getExecutablePath(env environment.Environment) (string, error) { executable = strings.ReplaceAll(executable, " ", "\\ ") executable = strings.ReplaceAll(executable, "(", "\\(") executable = strings.ReplaceAll(executable, ")", "\\)") - return executable, nil } return executable, nil }