rdesktop2
bunsenstraat 1 year ago
parent 50b5f5083d
commit b4f616a2c9
  1. 4
      apps/remixdesktop/src/plugins/xtermPlugin.ts
  2. 22
      apps/remixdesktop/src/utils/findExecutable.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']
}

@ -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<string> {
export async function findExecutable(command: string, cwd?: string, paths?: string[]): Promise<string[]> {
// 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);
}
}
if (results.length > 0) {
return results;
}
return path.join(cwd, command);
return [];
}
Loading…
Cancel
Save