mac-helper 0.0.4 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/iterm.d.ts +1 -1
- package/lib/iterm.js +21 -6
- package/package.json +1 -1
- package/src/iterm.ts +32 -9
package/lib/iterm.d.ts
CHANGED
package/lib/iterm.js
CHANGED
|
@@ -2,15 +2,30 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.iTerm = exports.runInIterm = void 0;
|
|
4
4
|
const run_1 = require("@jxa/run");
|
|
5
|
-
async function runInIterm(command) {
|
|
6
|
-
await (0, run_1.run)((command) => {
|
|
5
|
+
async function runInIterm(command, reuse = true) {
|
|
6
|
+
await (0, run_1.run)((command, reuse) => {
|
|
7
7
|
const app = Application('iTerm');
|
|
8
8
|
app.includeStandardAdditions = true;
|
|
9
9
|
app.activate();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
let usingSession;
|
|
11
|
+
// reuse when possible
|
|
12
|
+
if (reuse) {
|
|
13
|
+
const session = app.currentWindow().currentSession();
|
|
14
|
+
const isIdle = session.isAtShellPrompt();
|
|
15
|
+
if (isIdle) {
|
|
16
|
+
usingSession = session;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
// create new tab when necessary
|
|
20
|
+
if (!usingSession) {
|
|
21
|
+
const tab = app.createTabWithDefaultProfile(app.currentWindow);
|
|
22
|
+
usingSession = tab.currentSession();
|
|
23
|
+
}
|
|
24
|
+
if (!usingSession) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
app.write(usingSession, { text: command });
|
|
28
|
+
}, command, reuse);
|
|
14
29
|
}
|
|
15
30
|
exports.runInIterm = runInIterm;
|
|
16
31
|
exports.iTerm = {
|
package/package.json
CHANGED
package/src/iterm.ts
CHANGED
|
@@ -1,16 +1,39 @@
|
|
|
1
1
|
import { run } from '@jxa/run'
|
|
2
2
|
import { iTerm2 } from 'jxa-common-used'
|
|
3
3
|
|
|
4
|
-
export async function runInIterm(command: string) {
|
|
5
|
-
await run(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
export async function runInIterm(command: string, reuse = true) {
|
|
5
|
+
await run(
|
|
6
|
+
(command, reuse) => {
|
|
7
|
+
const app = Application<iTerm2>('iTerm')
|
|
8
|
+
app.includeStandardAdditions = true
|
|
9
|
+
app.activate()
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
let usingSession: iTerm2.Session | undefined
|
|
12
|
+
|
|
13
|
+
// reuse when possible
|
|
14
|
+
if (reuse) {
|
|
15
|
+
const session: iTerm2.Session = app.currentWindow().currentSession()
|
|
16
|
+
const isIdle = session.isAtShellPrompt()
|
|
17
|
+
if (isIdle) {
|
|
18
|
+
usingSession = session
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// create new tab when necessary
|
|
23
|
+
if (!usingSession) {
|
|
24
|
+
const tab = app.createTabWithDefaultProfile(app.currentWindow)
|
|
25
|
+
usingSession = tab.currentSession()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!usingSession) {
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
app.write(usingSession, { text: command })
|
|
33
|
+
},
|
|
34
|
+
command,
|
|
35
|
+
reuse
|
|
36
|
+
)
|
|
14
37
|
}
|
|
15
38
|
|
|
16
39
|
export const iTerm = {
|