From b4f616a2c9067223432e79d6083f75343d40b4e3 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Tue, 4 Jul 2023 17:02:29 +0200 Subject: [PATCH] fix bash --- apps/remixdesktop/src/plugins/xtermPlugin.ts | 4 +++- apps/remixdesktop/src/utils/findExecutable.ts | 22 ++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/apps/remixdesktop/src/plugins/xtermPlugin.ts b/apps/remixdesktop/src/plugins/xtermPlugin.ts index bf74143543..fe717e4b33 100644 --- a/apps/remixdesktop/src/plugins/xtermPlugin.ts +++ b/apps/remixdesktop/src/plugins/xtermPlugin.ts @@ -90,7 +90,9 @@ class XtermPluginClient extends ElectronBasePluginClient { if(os.platform() === 'win32') { const bash = await findExecutable('bash.exe') if(bash) { - return [bash, 'powershell.exe', 'cmd.exe'] + const shells = ['powershell.exe', 'cmd.exe', ...bash] + // filter out duplicates + return shells.filter((v, i, a) => a.indexOf(v) === i) } return ['powershell.exe', 'cmd.exe'] } diff --git a/apps/remixdesktop/src/utils/findExecutable.ts b/apps/remixdesktop/src/utils/findExecutable.ts index 0df91e4c7b..aea1d7412a 100644 --- a/apps/remixdesktop/src/utils/findExecutable.ts +++ b/apps/remixdesktop/src/utils/findExecutable.ts @@ -3,10 +3,10 @@ import process from "process"; import { Stats } from "fs"; import fs from 'fs/promises' -export async function findExecutable(command: string, cwd?: string, paths?: string[]): Promise { +export async function findExecutable(command: string, cwd?: string, paths?: string[]): Promise { // If we have an absolute path then we take it. if (path.isAbsolute(command)) { - return command; + return [command]; } if (cwd === undefined) { cwd = process.cwd(); @@ -17,7 +17,7 @@ export async function findExecutable(command: string, cwd?: string, paths?: stri if (dir !== '.') { // We have a directory and the directory is relative (see above). Make the path absolute // to the current working directory. - return path.join(cwd, command); + return [path.join(cwd, command)]; } @@ -27,7 +27,7 @@ export async function findExecutable(command: string, cwd?: string, paths?: stri } // No PATH environment. Make path absolute to the cwd. if (paths === undefined || paths.length === 0) { - return path.join(cwd, command); + return []; } @@ -55,6 +55,9 @@ export async function findExecutable(command: string, cwd?: string, paths?: stri // We have a simple file name. We get the path variable from the env // and try to find the executable on the path. + + const results = []; + for (const pathEntry of paths) { // The path entry is absolute. @@ -65,16 +68,19 @@ export async function findExecutable(command: string, cwd?: string, paths?: stri fullPath = path.join(cwd, pathEntry, command); } if (await fileExists(fullPath)) { - return fullPath; + results.push(fullPath); } let withExtension = fullPath + '.com'; if (await fileExists(withExtension)) { - return withExtension; + results.push(withExtension); } withExtension = fullPath + '.exe'; if (await fileExists(withExtension)) { - return withExtension; + results.push(withExtension); } } - return path.join(cwd, command); + if (results.length > 0) { + return results; + } + return []; } \ No newline at end of file