Skip to content

Commit

Permalink
Fix monitoring for Command Prompt (#1234)
Browse files Browse the repository at this point in the history
* Fix monitoring

- Fix monitoring for Command Prompt
- Fix "Git Bash" white space support

* Fix getting the user's shell

* Fix lint
  • Loading branch information
radurentea authored Jul 18, 2024
1 parent 91590cc commit fa6d630
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 19 deletions.
9 changes: 7 additions & 2 deletions src/espIdf/monitor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}'`;
}
Expand Down Expand Up @@ -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(" "));
Expand Down
22 changes: 5 additions & 17 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit fa6d630

Please sign in to comment.