Skip to content

Commit 540b1c5

Browse files
committed
Add support for terminal interception on OSX
1 parent b38998b commit 540b1c5

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
declare module 'osx-find-executable' {
2+
function findExecutable(bundleId: string, callback: (error: Error | null, executablePath?: string) => void): void;
3+
4+
export = findExecutable;
5+
}

package-lock.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"lodash": "^4.17.11",
4040
"mockttp": "^0.12.6",
4141
"node-gsettings-wrapper": "^0.5.0",
42+
"osx-find-executable": "^1.0.0",
4243
"rimraf": "^2.6.2",
4344
"tslib": "^1.9.3"
4445
},

src/interceptors/fresh-terminal.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { spawn, ChildProcess, SpawnOptions } from 'child_process';
55
import * as GSettings from 'node-gsettings-wrapper';
66
import * as commandExists from 'command-exists';
77

8+
import findOsxExecutableCb = require('osx-find-executable');
9+
const findOsxExecutable = util.promisify(findOsxExecutableCb);
10+
811
import { Interceptor } from '.';
912
import { HtkConfig } from '../config';
1013

@@ -42,7 +45,21 @@ const getTerminalCommand = _.memoize(async (): Promise<SpawnArgs | null> => {
4245
return { command: 'xterm' };
4346
}
4447
} else if (process.platform === 'darwin') {
45-
return null; // Coming soon
48+
const terminalExecutables = (await Promise.all(
49+
[
50+
'co.zeit.hyper',
51+
'com.googlecode.iterm2',
52+
'com.googlecode.iterm',
53+
'com.apple.Terminal'
54+
].map(
55+
(bundleId) => findOsxExecutable(bundleId).catch(() => null)
56+
)
57+
)).filter((executablePath) => !!executablePath);
58+
59+
const bestAvailableTerminal = terminalExecutables[0];
60+
if (bestAvailableTerminal) {
61+
return { command: bestAvailableTerminal };
62+
}
4663
}
4764

4865
return null;

0 commit comments

Comments
 (0)