From fa6d6304a10bad2a30e79434da432cfeffed802a Mon Sep 17 00:00:00 2001 From: Radu Date: Thu, 18 Jul 2024 13:00:05 +0300 Subject: [PATCH] Fix monitoring for Command Prompt (#1234) * Fix monitoring - Fix monitoring for Command Prompt - Fix "Git Bash" white space support * Fix getting the user's shell * Fix lint --- src/espIdf/monitor/index.ts | 9 +++++++-- src/utils.ts | 22 +++++----------------- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/espIdf/monitor/index.ts b/src/espIdf/monitor/index.ts index d607aa789..e14c1f812 100644 --- a/src/espIdf/monitor/index.ts +++ b/src/espIdf/monitor/index.ts @@ -64,8 +64,10 @@ export class IDFMonitor { // Function to quote paths for PowerShell and correctly handle spaces for Bash const quotePath = (path) => { - if (shellType === "PowerShell") { + if (shellType.includes("powershell")) { return `'${path.replace(/'/g, "''")}'`; + } else if (shellType.includes("cmd")) { + return `"${path}"`; } else { return `'${path}'`; } @@ -111,9 +113,12 @@ export class IDFMonitor { const envSetCmd = process.platform === "win32" ? "set" : "export"; const quotedIdfPath = quotePath(modifiedEnv.IDF_PATH); - if (shellType === "PowerShell") { + if (shellType.includes("powershell")) { this.terminal.sendText(`& ${envSetCmd} IDF_PATH=${quotedIdfPath}`); this.terminal.sendText(`& ${args.join(" ")}`); + } else if (shellType.includes("cmd")) { + this.terminal.sendText(`${envSetCmd} IDF_PATH=${modifiedEnv.IDF_PATH}`); + this.terminal.sendText(args.join(" ")); } else { this.terminal.sendText(`${envSetCmd} IDF_PATH=${quotedIdfPath}`); this.terminal.sendText(args.join(" ")); diff --git a/src/utils.ts b/src/utils.ts index 3364895f2..7cf98b56c 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1255,34 +1255,22 @@ export function markdownToWebviewHtml( } export function getUserShell() { - if (idfConf.readParameter("idf.customTerminalExecutable")) { - return "custom"; - } - - const config = vscode.workspace.getConfiguration("terminal.integrated"); - - const shellWindows = config.get("defaultProfile.windows") as string; - const shellMac = config.get("defaultProfile.osx") as string; - const shellLinux = config.get("defaultProfile.linux") as string; + const shell = vscode.env.shell; // list of shells to check - const shells = ["PowerShell", "Command Prompt", "bash", "zsh"]; + const shells = ["powershell", "cmd", "bash", "zsh"]; // if user's shell is in the list, return it for (let i = 0; i < shells.length; i++) { - if (shellWindows && shellWindows.includes(shells[i])) { - return shells[i]; - } else if (shellMac && shellMac.includes(shells[i])) { - return shells[i]; - } else if (shellLinux && shellLinux.includes(shells[i])) { + if (shell && shell.includes(shells[i])) { return shells[i]; } } - // if no match or no defaultProfile, pick one based on user's OS + // if no match, pick one based on user's OS const userOS = platform(); if (userOS === "win32") { - return "PowerShell"; + return "powershell"; } else if (userOS === "darwin") { return "zsh"; } else if (userOS === "linux") {