Skip to content

Commit bb36fa0

Browse files
committed
Check that the configured linux terminal actually exists before running it
1 parent 31e9461 commit bb36fa0

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/interceptors/fresh-terminal.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ import * as fs from 'fs';
33
import * as util from 'util';
44
import { spawn, ChildProcess, SpawnOptions } from 'child_process';
55
import * as GSettings from 'node-gsettings-wrapper';
6-
import * as commandExists from 'command-exists';
6+
import * as ensureCommandExists from 'command-exists';
77

88
import findOsxExecutableCb = require('osx-find-executable');
99
const findOsxExecutable = util.promisify(findOsxExecutableCb);
1010

1111
import { Interceptor } from '.';
1212
import { HtkConfig } from '../config';
13+
import { reportError } from '../error-tracking';
1314

1415
const checkAccess = util.promisify(fs.access);
1516
const canAccess = (path: string) => checkAccess(path).then(() => true).catch(() => false);
1617

18+
const commandExists = (path: string) => ensureCommandExists(path).then(() => true).catch(() => false);
19+
1720
const DEFAULT_GIT_BASH_PATH = 'C:/Program Files/git/git-bash.exe';
1821

1922
interface SpawnArgs {
@@ -24,7 +27,7 @@ interface SpawnArgs {
2427

2528
const getTerminalCommand = _.memoize(async (): Promise<SpawnArgs | null> => {
2629
if (process.platform === 'win32') {
27-
if (await commandExists('git-bash').catch(() => false)) {
30+
if (await commandExists('git-bash')) {
2831
return { command: 'git-bash' };
2932
} else if (await canAccess(DEFAULT_GIT_BASH_PATH)) {
3033
return { command: DEFAULT_GIT_BASH_PATH };
@@ -38,10 +41,12 @@ const getTerminalCommand = _.memoize(async (): Promise<SpawnArgs | null> => {
3841
);
3942

4043
const defaultTerminal = gSettingsTerminalKey && gSettingsTerminalKey.getValue();
41-
if (defaultTerminal) return { command: defaultTerminal };
44+
if (defaultTerminal && commandExists(defaultTerminal)) {
45+
return { command: defaultTerminal };
46+
}
4247
}
4348

44-
if (await commandExists('xterm').catch(() => false)) {
49+
if (await commandExists('xterm')) {
4550
return { command: 'xterm' };
4651
}
4752
} else if (process.platform === 'darwin') {

0 commit comments

Comments
 (0)