@noldova/terminal 0.0.16 → 0.0.18
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/module.json +2 -2
- package/package.json +9 -9
- package/src/enums/mark-kind.js +1 -0
- package/src/enums/shell-family.js +1 -0
- package/src/exceptions/command-exited.exception.js +2 -1
- package/src/models/hosted-terminal.js +20 -9
- package/src/models/one-shot-launch.js +7 -4
- package/src/models/right-prompt-span.js +14 -0
- package/src/models/terminal-prompt.js +5 -5
- package/src/models/typed-line.js +2 -2
- package/src/resources.js +271 -13
- package/src/runtime-part.js +1 -1
- package/src/services/agent-terminal.js +7 -5
- package/src/services/command-describer.js +35 -33
- package/src/services/command-runner.js +5 -3
- package/src/services/command-tracker.js +17 -2
- package/src/services/completion-source.js +62 -30
- package/src/services/escape-sequence-tracker.js +1 -1
- package/src/services/escape-stripper.js +10 -7
- package/src/services/file-system.reader.js +2 -1
- package/src/services/fish-shell-adapter.js +90 -0
- package/src/services/folder-change-line.js +2 -0
- package/src/services/line-process.js +3 -2
- package/src/services/log-file.js +4 -3
- package/src/services/mac-environment.js +5 -2
- package/src/services/mark-scanner.js +5 -5
- package/src/services/output-batcher.js +1 -1
- package/src/services/output-log.js +2 -1
- package/src/services/posix-shell-adapter.js +3 -2
- package/src/services/printed-text.js +3 -2
- package/src/services/pseudo-terminal.js +1 -1
- package/src/services/registry-export.js +5 -5
- package/src/services/resize-wakeup.js +1 -1
- package/src/services/saved-terminals.js +2 -1
- package/src/services/shell-adapters.js +3 -1
- package/src/services/shell-command.js +7 -2
- package/src/services/shell-integration.js +32 -14
- package/src/services/shell-locator.js +27 -13
- package/src/services/shell-words.js +5 -5
- package/src/services/terminal-history-segment.js +1 -1
- package/src/services/terminal-host.js +166 -45
- package/src/services/terminal-line-reader.js +9 -3
- package/src/services/terminal-mirror.js +12 -11
- package/src/services/terminal-session.js +24 -8
- package/src/services/wsl-distribution.reader.js +5 -2
- package/src/services/wsl-shell-adapter.js +6 -2
- package/src/tools/models/output-excerpt.js +2 -1
- package/src/tools/models/terminal-output-report.js +4 -2
- package/src/tools/models/tool-call-context.js +2 -1
- package/src/tools/services/terminal-access-policy.js +4 -2
- package/src/tools/services/terminal-text-escaper.js +4 -2
- package/src/tools/services/terminal-write-tool.js +5 -3
package/src/services/log-file.js
CHANGED
|
@@ -5,12 +5,13 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { Resources } from "../resources.js";
|
|
9
10
|
import { FailureText } from "./failure-text.js";
|
|
10
11
|
export class LogFile {
|
|
11
12
|
writer;
|
|
12
13
|
log;
|
|
13
|
-
pending =
|
|
14
|
+
pending = String.empty;
|
|
14
15
|
length = 0;
|
|
15
16
|
writing = Promise.resolve();
|
|
16
17
|
isWriting = false;
|
|
@@ -42,7 +43,7 @@ export class LogFile {
|
|
|
42
43
|
async writePendingAsync() {
|
|
43
44
|
while (this.pending.length > 0 && !this.hasFailed) {
|
|
44
45
|
const text = this.pending;
|
|
45
|
-
this.pending =
|
|
46
|
+
this.pending = String.empty;
|
|
46
47
|
try {
|
|
47
48
|
await this.writer.appendTextAsync(this.path, text);
|
|
48
49
|
}
|
|
@@ -51,7 +52,7 @@ export class LogFile {
|
|
|
51
52
|
this.log.write(Resources.formatLogFailed(this.path, FailureText.read(error)));
|
|
52
53
|
}
|
|
53
54
|
}
|
|
54
|
-
this.pending =
|
|
55
|
+
this.pending = String.empty;
|
|
55
56
|
this.isWriting = false;
|
|
56
57
|
}
|
|
57
58
|
}
|
|
@@ -31,7 +31,7 @@ export class MacEnvironment {
|
|
|
31
31
|
void this.readAsync().catch(() => undefined);
|
|
32
32
|
}
|
|
33
33
|
readAsync() {
|
|
34
|
-
this.reading ??= Resources.localeVariables.some(t => (this.environment[t] ??
|
|
34
|
+
this.reading ??= Resources.localeVariables.some(t => (this.environment[t] ?? String.empty) !== String.empty)
|
|
35
35
|
? Promise.resolve(this.environment)
|
|
36
36
|
: this.readLocaleAsync().then(t => this.withUtf8LocaleAsync(t)).catch((error) => {
|
|
37
37
|
this.reading = null;
|
|
@@ -71,7 +71,10 @@ export class MacEnvironment {
|
|
|
71
71
|
}
|
|
72
72
|
static toLocale(line) {
|
|
73
73
|
try {
|
|
74
|
-
return new Intl.Locale(line
|
|
74
|
+
return new Intl.Locale(line
|
|
75
|
+
.replace(Resources.macEnvironmentLocaleModifier, String.empty)
|
|
76
|
+
.replaceAll(Resources.macEnvironmentLocaleSeparator, Resources.macEnvironmentLanguageTagSeparator))
|
|
77
|
+
.toString();
|
|
75
78
|
}
|
|
76
79
|
catch (error) {
|
|
77
80
|
if (error instanceof RangeError)
|
|
@@ -17,7 +17,7 @@ const TERMINATORS = [Resources.bell, Resources.eightBitStringTerminator];
|
|
|
17
17
|
const CANCELS = [Resources.cancel, Resources.substitute];
|
|
18
18
|
export class MarkScanner {
|
|
19
19
|
nonce;
|
|
20
|
-
carry =
|
|
20
|
+
carry = String.empty;
|
|
21
21
|
constructor(nonce) {
|
|
22
22
|
this.nonce = nonce;
|
|
23
23
|
}
|
|
@@ -25,7 +25,7 @@ export class MarkScanner {
|
|
|
25
25
|
const text = this.carry + data;
|
|
26
26
|
const textOffset = offset - this.carry.length;
|
|
27
27
|
const marks = [];
|
|
28
|
-
this.carry =
|
|
28
|
+
this.carry = String.empty;
|
|
29
29
|
let index = 0;
|
|
30
30
|
while (index < text.length) {
|
|
31
31
|
const introducer = MarkScanner.findIntroducer(text, index);
|
|
@@ -58,7 +58,7 @@ export class MarkScanner {
|
|
|
58
58
|
return marks;
|
|
59
59
|
}
|
|
60
60
|
parse(payload, offset) {
|
|
61
|
-
const [kindText, nonce, ...values] = payload.replace(Resources.markScannerIgnoredControl,
|
|
61
|
+
const [kindText, nonce, ...values] = payload.replace(Resources.markScannerIgnoredControl, String.empty).split(Resources.markScannerFieldSeparator);
|
|
62
62
|
const kind = Resources.markKindLetters.get(String(kindText));
|
|
63
63
|
if (Object.isUndefined(kind) || nonce !== this.nonce)
|
|
64
64
|
return null;
|
|
@@ -83,7 +83,7 @@ export class MarkScanner {
|
|
|
83
83
|
return new MarkTerminator(-1, -1);
|
|
84
84
|
}
|
|
85
85
|
static findIntroducer(text, from) {
|
|
86
|
-
let found = new MarkIntroducer(-1,
|
|
86
|
+
let found = new MarkIntroducer(-1, String.empty);
|
|
87
87
|
for (const introducer of INTRODUCERS) {
|
|
88
88
|
const start = text.indexOf(introducer, from);
|
|
89
89
|
if (start >= 0 && (found.start < 0 || start < found.start))
|
|
@@ -97,6 +97,6 @@ export class MarkScanner {
|
|
|
97
97
|
if (INTRODUCERS.some(t => t.startsWith(prefix)))
|
|
98
98
|
return prefix;
|
|
99
99
|
}
|
|
100
|
-
return
|
|
100
|
+
return String.empty;
|
|
101
101
|
}
|
|
102
102
|
}
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { Registration } from "@noldova/desktop.runtime";
|
|
9
10
|
import { Resources } from "../resources.js";
|
|
10
11
|
import { OutputChunk } from "../tools/models/output-chunk.js";
|
|
@@ -13,7 +14,7 @@ export class OutputLog {
|
|
|
13
14
|
stripper = new EscapeStripper();
|
|
14
15
|
limit;
|
|
15
16
|
listeners = new Set();
|
|
16
|
-
text =
|
|
17
|
+
text = String.empty;
|
|
17
18
|
startOffset = 0;
|
|
18
19
|
constructor(limit = Resources.maximumAgentTextLength) {
|
|
19
20
|
this.limit = limit;
|
|
@@ -49,8 +49,9 @@ export class PosixShellAdapter {
|
|
|
49
49
|
if (!this.isGitBash || !value.startsWith(Resources.posixSeparator))
|
|
50
50
|
return value;
|
|
51
51
|
const temporary = Resources.gitBashTemporaryFolder;
|
|
52
|
-
if (!Object.isNull(temporaryFolder) &&
|
|
53
|
-
|
|
52
|
+
if (!Object.isNull(temporaryFolder) &&
|
|
53
|
+
path.win32.isAbsolute(temporaryFolder) &&
|
|
54
|
+
(value === temporary || value.startsWith(`${temporary}${Resources.posixSeparator}`)))
|
|
54
55
|
return path.win32.join(temporaryFolder, value.slice(temporary.length));
|
|
55
56
|
if (!Resources.gitBashDrivePath.test(value))
|
|
56
57
|
return null;
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
* This source code is licensed under the license found in the
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
|
+
import "@noldova/context.core";
|
|
8
9
|
import { Resources } from "../resources.js";
|
|
9
10
|
import { EscapeStripper } from "./escape-stripper.js";
|
|
10
11
|
export class PrintedText {
|
|
@@ -32,9 +33,9 @@ export class PrintedText {
|
|
|
32
33
|
return !PrintedText.isBlank(this.line) && !PrintedText.isLineEndMark(this.line);
|
|
33
34
|
}
|
|
34
35
|
static isBlank(line) {
|
|
35
|
-
return line.join(
|
|
36
|
+
return line.join(String.empty).trim().length === 0;
|
|
36
37
|
}
|
|
37
38
|
static isLineEndMark(line) {
|
|
38
|
-
return Resources.lineEndMarks.includes(line.join(
|
|
39
|
+
return Resources.lineEndMarks.includes(line.join(String.empty).trimEnd());
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -20,7 +20,7 @@ export class PseudoTerminal {
|
|
|
20
20
|
isRequestShared = false;
|
|
21
21
|
requestTime = Number.NEGATIVE_INFINITY;
|
|
22
22
|
hasOutput = false;
|
|
23
|
-
outputEnd =
|
|
23
|
+
outputEnd = String.empty;
|
|
24
24
|
answerLimit = undefined;
|
|
25
25
|
constructor(process, listener, isConPty = false, asksAfterResize = isConPty) {
|
|
26
26
|
this.process = process;
|
|
@@ -38,7 +38,7 @@ export class RegistryExport {
|
|
|
38
38
|
if (this.text[this.index] === Resources.registryExportQuote) {
|
|
39
39
|
const value = this.readQuoted();
|
|
40
40
|
this.readData();
|
|
41
|
-
if (name !==
|
|
41
|
+
if (name !== String.empty)
|
|
42
42
|
values.set(name, new RegistryValue(value, false));
|
|
43
43
|
continue;
|
|
44
44
|
}
|
|
@@ -49,13 +49,13 @@ export class RegistryExport {
|
|
|
49
49
|
const type = this.text.slice(this.index, typeEnd);
|
|
50
50
|
this.index = typeEnd + 1;
|
|
51
51
|
const data = this.readData();
|
|
52
|
-
if (name !==
|
|
52
|
+
if (name !== String.empty && (type === Resources.registryExportExpandableType || type === Resources.registryExportTextType))
|
|
53
53
|
values.set(name, new RegistryValue(RegistryExport.decode(data), type === Resources.registryExportExpandableType));
|
|
54
54
|
}
|
|
55
55
|
return values;
|
|
56
56
|
}
|
|
57
57
|
readQuoted() {
|
|
58
|
-
let value =
|
|
58
|
+
let value = String.empty;
|
|
59
59
|
this.index++;
|
|
60
60
|
for (;;) {
|
|
61
61
|
const character = this.text[this.index];
|
|
@@ -79,7 +79,7 @@ export class RegistryExport {
|
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
81
|
readData() {
|
|
82
|
-
let data =
|
|
82
|
+
let data = String.empty;
|
|
83
83
|
let isFirst = true;
|
|
84
84
|
for (;;) {
|
|
85
85
|
const end = this.text.indexOf(Resources.lineFeed, this.index);
|
|
@@ -96,7 +96,7 @@ export class RegistryExport {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
static decode(data) {
|
|
99
|
-
const bytes = data.trim() ===
|
|
99
|
+
const bytes = data.trim() === String.empty ? [] : data.split(Resources.registryExportByteSeparator).map(t => {
|
|
100
100
|
const digits = t.trim();
|
|
101
101
|
if (!Resources.registryExportByteDigits.test(digits))
|
|
102
102
|
throw new EnvironmentExportInvalidException();
|
|
@@ -24,7 +24,8 @@ export class SavedTerminals {
|
|
|
24
24
|
this.log = log;
|
|
25
25
|
}
|
|
26
26
|
list() {
|
|
27
|
-
return this.database
|
|
27
|
+
return this.database
|
|
28
|
+
.readAll(Resources.savedTerminalsListQuery)
|
|
28
29
|
.map(t => new SavedTerminal(String(t[Resources.savedTerminalsSessionIdColumn]), String(t[Resources.savedTerminalsShellIdColumn]), String(t[Resources.savedTerminalsFolderColumn]), Number(t[Resources.savedTerminalsIsPanelTerminalColumn]) === 1, Object.isNull(t[Resources.savedTerminalsOwnerColumn]) ? null : String(t[Resources.savedTerminalsOwnerColumn]), Number(t[Resources.savedTerminalsOpensTabColumn]) === 1, Object.isNull(t[Resources.savedTerminalsNameColumn]) ? null : String(t[Resources.savedTerminalsNameColumn])));
|
|
29
30
|
}
|
|
30
31
|
save(terminal) {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import "@noldova/context.core";
|
|
9
9
|
import { TerminalShellKind } from "@noldova/terminal.protocol";
|
|
10
10
|
import { Resources } from "../resources.js";
|
|
11
|
+
import { FishShellAdapter } from "./fish-shell-adapter.js";
|
|
11
12
|
import { PosixShellAdapter } from "./posix-shell-adapter.js";
|
|
12
13
|
import { PowerShellShellAdapter } from "./powershell-shell-adapter.js";
|
|
13
14
|
import { WslShellAdapter } from "./wsl-shell-adapter.js";
|
|
@@ -18,7 +19,8 @@ export class ShellAdapters {
|
|
|
18
19
|
this.adapters = new Map([
|
|
19
20
|
[TerminalShellKind.PowerShell, new PowerShellShellAdapter(isWindows)],
|
|
20
21
|
[TerminalShellKind.Bash, new PosixShellAdapter(isWindows, null, null, true)],
|
|
21
|
-
[TerminalShellKind.Zsh, new PosixShellAdapter(isWindows, Resources.zshOptionsKeys, Resources.zshFolderKeys, false)]
|
|
22
|
+
[TerminalShellKind.Zsh, new PosixShellAdapter(isWindows, Resources.zshOptionsKeys, Resources.zshFolderKeys, false)],
|
|
23
|
+
[TerminalShellKind.Fish, new FishShellAdapter()]
|
|
22
24
|
]);
|
|
23
25
|
}
|
|
24
26
|
of(shell) {
|
|
@@ -49,7 +49,11 @@ export class ShellCommand {
|
|
|
49
49
|
return Object.isNull(this.givenUp) ? this.tracked?.cwd ?? null : null;
|
|
50
50
|
}
|
|
51
51
|
get hasEnded() {
|
|
52
|
-
return !Object.isNull(this.givenUp) ||
|
|
52
|
+
return !Object.isNull(this.givenUp) ||
|
|
53
|
+
this.tracked?.hasEnded === true ||
|
|
54
|
+
!Object.isNull(this.unmarkedEnd) ||
|
|
55
|
+
!Object.isNull(this.restartEnd) ||
|
|
56
|
+
this.session.hasExited;
|
|
53
57
|
}
|
|
54
58
|
get outputStart() {
|
|
55
59
|
if (!Object.isNull(this.givenUp))
|
|
@@ -88,7 +92,8 @@ export class ShellCommand {
|
|
|
88
92
|
return;
|
|
89
93
|
this.givenUp = new OutputSpan(this.outputStart, this.outputEnd);
|
|
90
94
|
this.session.changes.notify();
|
|
91
|
-
}, Resources.graceMilliseconds)
|
|
95
|
+
}, Resources.graceMilliseconds)
|
|
96
|
+
.unref();
|
|
92
97
|
return true;
|
|
93
98
|
}
|
|
94
99
|
}
|
|
@@ -34,22 +34,18 @@ export class ShellIntegration {
|
|
|
34
34
|
async prepareAsync(shell, nonce, environment, note = null) {
|
|
35
35
|
const launch = await this.prepareShellAsync(shell, nonce, environment, note);
|
|
36
36
|
return this.platform === Resources.macPlatform && ShellIntegration.toFamily(shell.file) === ShellFamily.PowerShell
|
|
37
|
-
? ShellIntegration.toPowerShellLoginLaunch(launch)
|
|
37
|
+
? ShellIntegration.toPowerShellLoginLaunch(launch)
|
|
38
|
+
: launch;
|
|
38
39
|
}
|
|
39
40
|
watch(process, launch) {
|
|
40
41
|
const { nonce, nonceFile } = launch;
|
|
41
42
|
if (Object.isNull(nonce) || Object.isNull(nonceFile))
|
|
42
43
|
return;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
exit.dispose();
|
|
46
|
-
void this.removeNonceFileAsync(nonceFile);
|
|
47
|
-
};
|
|
48
|
-
const data = process.onData(t => {
|
|
44
|
+
const watchers = [];
|
|
45
|
+
watchers.push(process.onData(t => {
|
|
49
46
|
if (t.includes(nonce))
|
|
50
|
-
|
|
51
|
-
});
|
|
52
|
-
const exit = process.onExit(() => remove());
|
|
47
|
+
this.endWatch(watchers, nonceFile);
|
|
48
|
+
}), process.onExit(() => this.endWatch(watchers, nonceFile)));
|
|
53
49
|
}
|
|
54
50
|
async removeNonceFileAsync(nonceFile) {
|
|
55
51
|
if (Object.isNull(nonceFile))
|
|
@@ -84,6 +80,11 @@ export class ShellIntegration {
|
|
|
84
80
|
this.log.write(Resources.formatSuggestionsUnwatched(FailureText.read(error)));
|
|
85
81
|
}
|
|
86
82
|
}
|
|
83
|
+
endWatch(watchers, nonceFile) {
|
|
84
|
+
for (const watcher of watchers)
|
|
85
|
+
watcher.dispose();
|
|
86
|
+
void this.removeNonceFileAsync(nonceFile);
|
|
87
|
+
}
|
|
87
88
|
async prepareShellAsync(shell, nonce, environment, note) {
|
|
88
89
|
const family = ShellIntegration.toFamily(shell.file);
|
|
89
90
|
if (family === ShellFamily.CommandPrompt)
|
|
@@ -108,7 +109,9 @@ export class ShellIntegration {
|
|
|
108
109
|
}, nonce, nonceFile, !Object.isNull(note));
|
|
109
110
|
if (family === ShellFamily.PowerShell)
|
|
110
111
|
return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellIntegrationArguments, ShellIntegration.encode([Resources.shellIntegrationPowerShellNonce, Resources.shellIntegrationPowerShellNote, Resources.shellIntegrationPowerShellProfiles, shell.startCommand,
|
|
111
|
-
Resources.shellIntegrationPowerShellScript]
|
|
112
|
+
Resources.shellIntegrationPowerShellScript]
|
|
113
|
+
.filter(t => !Object.isNull(t))
|
|
114
|
+
.join(Resources.lineFeed))], {
|
|
112
115
|
[Resources.nonceFileVariable]: nonceFile,
|
|
113
116
|
...noteVariables
|
|
114
117
|
}, nonce, nonceFile, !Object.isNull(note));
|
|
@@ -121,6 +124,15 @@ export class ShellIntegration {
|
|
|
121
124
|
...noteVariables
|
|
122
125
|
}, nonce, nonceFile, !Object.isNull(note));
|
|
123
126
|
}
|
|
127
|
+
if (family === ShellFamily.Fish) {
|
|
128
|
+
const dataFolders = environment[Resources.dataFoldersVariable] ?? String.empty;
|
|
129
|
+
return new ShellLaunch(shell.file, shell.args, {
|
|
130
|
+
[Resources.nonceFileVariable]: nonceFile,
|
|
131
|
+
[Resources.dataFoldersVariable]: [folder, dataFolders === String.empty ? Resources.defaultDataFolders : dataFolders].join(path.posix.delimiter),
|
|
132
|
+
[Resources.userDataFoldersVariable]: dataFolders,
|
|
133
|
+
...noteVariables
|
|
134
|
+
}, nonce, nonceFile, !Object.isNull(note));
|
|
135
|
+
}
|
|
124
136
|
const userFolder = environment[Resources.zdotdirVariable];
|
|
125
137
|
return new ShellLaunch(shell.file, shell.args, {
|
|
126
138
|
[Resources.nonceFileVariable]: nonceFile,
|
|
@@ -174,17 +186,21 @@ export class ShellIntegration {
|
|
|
174
186
|
const folder = await this.writer.createPrivateFolderAsync(path.join(this.temporaryFolder, Resources.integrationFolderPrefix));
|
|
175
187
|
try {
|
|
176
188
|
await this.access?.restrictAsync(folder);
|
|
189
|
+
for (let depth = 1; depth <= Resources.fishScriptFolder.length; depth++)
|
|
190
|
+
await this.writer.createMissingFolderAsync(path.join(folder, ...Resources.fishScriptFolder.slice(0, depth)), Resources.integrationFolderMode);
|
|
177
191
|
for (const script of [
|
|
178
192
|
new IntegrationScript(Resources.bashScriptFile, Resources.shellIntegrationBashScript),
|
|
179
193
|
new IntegrationScript(Resources.zshEnvironmentFile, Resources.shellIntegrationZshEnvironment),
|
|
180
194
|
new IntegrationScript(Resources.zshProfileFile, Resources.shellIntegrationZshProfile),
|
|
181
195
|
new IntegrationScript(Resources.zshInteractiveFile, Resources.shellIntegrationZshInteractive),
|
|
182
|
-
new IntegrationScript(Resources.zshLoginFile, Resources.shellIntegrationZshLogin)
|
|
196
|
+
new IntegrationScript(Resources.zshLoginFile, Resources.shellIntegrationZshLogin),
|
|
197
|
+
new IntegrationScript(path.join(...Resources.fishScriptFolder, Resources.fishScriptFile), Resources.shellIntegrationFishScript)
|
|
183
198
|
])
|
|
184
199
|
await this.writer.writeTextAsync(path.join(folder, script.fileName), script.text);
|
|
185
200
|
}
|
|
186
201
|
catch (error) {
|
|
187
|
-
await this.writer
|
|
202
|
+
await this.writer
|
|
203
|
+
.removeFolderAsync(folder)
|
|
188
204
|
.catch((removalError) => this.log.write(Resources.formatIntegrationRemovalFailed(FailureText.read(removalError))));
|
|
189
205
|
throw error;
|
|
190
206
|
}
|
|
@@ -217,6 +233,8 @@ export class ShellIntegration {
|
|
|
217
233
|
return ShellFamily.Bash;
|
|
218
234
|
case Resources.zshExecutable:
|
|
219
235
|
return ShellFamily.Zsh;
|
|
236
|
+
case Resources.fishExecutable:
|
|
237
|
+
return ShellFamily.Fish;
|
|
220
238
|
case Resources.cmdExecutable:
|
|
221
239
|
return ShellFamily.CommandPrompt;
|
|
222
240
|
case Resources.wslExecutable:
|
|
@@ -230,7 +248,7 @@ export class ShellIntegration {
|
|
|
230
248
|
}
|
|
231
249
|
static toWslEnvironment(environment, hasNote) {
|
|
232
250
|
const passed = Object.entries(environment).find(([t]) => t.toUpperCase() === Resources.wslEnvironmentVariable)?.[1];
|
|
233
|
-
return [...Object.isUndefined(passed) || passed ===
|
|
251
|
+
return [...Object.isUndefined(passed) || passed === String.empty ? [] : [passed], `${Resources.nonceFileVariable}${Resources.wslPathFlag}`,
|
|
234
252
|
`${Resources.integrationFolderVariable}${Resources.wslPathFlag}`, Resources.loginVariable, ...hasNote ? [Resources.noteVariable] : []]
|
|
235
253
|
.join(Resources.wslEnvironmentSeparator);
|
|
236
254
|
}
|
|
@@ -58,24 +58,25 @@ export class ShellLocator {
|
|
|
58
58
|
return [...installed, ...await this.locateListedAsync(installed)];
|
|
59
59
|
}
|
|
60
60
|
async findAsync(shellId) {
|
|
61
|
-
const isMatch = (shell) => Object.isNull(shellId) ? shell.isDefault : shell.id === shellId;
|
|
62
61
|
if (this.platform !== Resources.windowsPlatform)
|
|
63
|
-
return (await this.locateOnUnixAsync()).find(isMatch);
|
|
62
|
+
return (await this.locateOnUnixAsync()).find(t => ShellLocator.isMatch(t, shellId));
|
|
64
63
|
const installed = await this.locateOnWindowsAsync();
|
|
65
|
-
return installed.find(
|
|
64
|
+
return installed.find(t => ShellLocator.isMatch(t, shellId)) ??
|
|
65
|
+
(Object.isNull(shellId) ? undefined : (await this.locateListedAsync(installed)).find(t => ShellLocator.isMatch(t, shellId)));
|
|
66
66
|
}
|
|
67
67
|
async findKindAsync(kinds) {
|
|
68
|
-
const isMatch = (shell) => kinds.includes(shell.kind);
|
|
69
68
|
if (this.platform !== Resources.windowsPlatform)
|
|
70
|
-
return (await this.locateOnUnixAsync()).find(
|
|
69
|
+
return (await this.locateOnUnixAsync()).find(t => kinds.includes(t.kind));
|
|
71
70
|
const installed = await this.locateOnWindowsAsync();
|
|
72
|
-
return installed.find(
|
|
71
|
+
return installed.find(t => kinds.includes(t.kind)) ?? (await this.locateListedAsync(installed)).find(t => kinds.includes(t.kind));
|
|
73
72
|
}
|
|
74
73
|
async locateOnWindowsAsync() {
|
|
75
74
|
const programFiles = this.environment[Resources.programFilesVariable];
|
|
76
75
|
const localAppData = this.environment[Resources.localAppDataVariable];
|
|
77
76
|
const systemRoot = this.environment[Resources.systemRootVariable];
|
|
78
|
-
const searchPath = (this.environment[Resources.pathVariable] ??
|
|
77
|
+
const searchPath = (this.environment[Resources.pathVariable] ?? String.empty)
|
|
78
|
+
.split(path.win32.delimiter)
|
|
79
|
+
.filter(t => path.win32.isAbsolute(t));
|
|
79
80
|
const gitFolders = [
|
|
80
81
|
...ShellLocator.joinIfSet(programFiles, Resources.gitFolder),
|
|
81
82
|
...ShellLocator.joinIfSet(this.environment[Resources.programFilesX86Variable], Resources.gitFolder),
|
|
@@ -101,20 +102,29 @@ export class ShellLocator {
|
|
|
101
102
|
return shells;
|
|
102
103
|
}
|
|
103
104
|
async locateOnUnixAsync() {
|
|
104
|
-
const listed = (await this.fileSystem.readTextOrNullAsync(Resources.shellsFile) ??
|
|
105
|
+
const listed = (await this.fileSystem.readTextOrNullAsync(Resources.shellsFile) ?? String.empty)
|
|
105
106
|
.split(Resources.lineFeed)
|
|
106
107
|
.map(t => t.trim())
|
|
107
|
-
.filter(t => t.startsWith(Resources.posixRoot)
|
|
108
|
+
.filter(t => t.startsWith(Resources.posixRoot));
|
|
108
109
|
const preferred = this.userShell ?? this.environment[Resources.shellVariable];
|
|
109
110
|
const files = Object.isUndefined(preferred) ? listed : [preferred, ...listed];
|
|
110
111
|
const args = [Resources.loginArgument];
|
|
111
112
|
const shells = [];
|
|
112
113
|
for (const file of files) {
|
|
113
114
|
const id = path.posix.basename(file);
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
const kind = Resources.unixShellKinds.get(id);
|
|
116
|
+
if (!Object.isUndefined(kind) && !shells.some(t => t.id === id) && await this.fileSystem.isFileAsync(file))
|
|
117
|
+
shells.push(new Shell(id, id, kind, file, args, shells.length === 0));
|
|
116
118
|
}
|
|
117
|
-
return shells;
|
|
119
|
+
return shells.length > 0 ? shells : this.locateSystemShellAsync(preferred, listed, args);
|
|
120
|
+
}
|
|
121
|
+
async locateSystemShellAsync(preferred, listed, args) {
|
|
122
|
+
const loginShell = !Object.isUndefined(preferred) && listed.includes(preferred) ? [preferred] : [];
|
|
123
|
+
for (const file of [...loginShell, Resources.systemShellFile]) {
|
|
124
|
+
if (await this.fileSystem.isFileAsync(file))
|
|
125
|
+
return [new Shell(path.posix.basename(file), path.posix.basename(file), TerminalShellKind.Other, file, args, true)];
|
|
126
|
+
}
|
|
127
|
+
return [];
|
|
118
128
|
}
|
|
119
129
|
async locateListedAsync(installed) {
|
|
120
130
|
const [wslShells, installations] = await Promise.all([this.locateWslShellsAsync(), this.readInstallationsAsync()]);
|
|
@@ -169,11 +179,15 @@ export class ShellLocator {
|
|
|
169
179
|
async findGitOnSearchPathAsync(searchPath) {
|
|
170
180
|
const folders = [];
|
|
171
181
|
for (const folder of searchPath) {
|
|
172
|
-
if (path.win32.basename(folder).toLowerCase() === Resources.gitCommandFolder &&
|
|
182
|
+
if (path.win32.basename(folder).toLowerCase() === Resources.gitCommandFolder &&
|
|
183
|
+
await this.fileSystem.isProgramAsync(path.win32.join(folder, Resources.gitExecutableFile)))
|
|
173
184
|
folders.push(path.win32.dirname(folder));
|
|
174
185
|
}
|
|
175
186
|
return folders;
|
|
176
187
|
}
|
|
188
|
+
static isMatch(shell, shellId) {
|
|
189
|
+
return Object.isNull(shellId) ? shell.isDefault : shell.id === shellId;
|
|
190
|
+
}
|
|
177
191
|
static joinIfSet(folder, names) {
|
|
178
192
|
return Object.isUndefined(folder) || folder.length === 0 ? [] : [path.win32.join(folder, ...names)];
|
|
179
193
|
}
|
|
@@ -12,7 +12,7 @@ export class ShellWords {
|
|
|
12
12
|
static read(text, isPowerShell) {
|
|
13
13
|
const escape = isPowerShell ? Resources.powerShellEscape : Resources.posixEscape;
|
|
14
14
|
let words = [];
|
|
15
|
-
let value =
|
|
15
|
+
let value = String.empty;
|
|
16
16
|
let start = text.length;
|
|
17
17
|
let isInWord = false;
|
|
18
18
|
let quote = null;
|
|
@@ -55,12 +55,12 @@ export class ShellWords {
|
|
|
55
55
|
else if (Resources.wordBreaks.includes(character)) {
|
|
56
56
|
if (isInWord)
|
|
57
57
|
words.push(value);
|
|
58
|
-
value =
|
|
58
|
+
value = String.empty;
|
|
59
59
|
isInWord = false;
|
|
60
60
|
}
|
|
61
61
|
else if (Resources.commandBreaks.includes(character)) {
|
|
62
62
|
words = [];
|
|
63
|
-
value =
|
|
63
|
+
value = String.empty;
|
|
64
64
|
isInWord = false;
|
|
65
65
|
}
|
|
66
66
|
else
|
|
@@ -72,10 +72,10 @@ export class ShellWords {
|
|
|
72
72
|
const literal = isPowerShell && escapesWildcards ? value.replace(Resources.powerShellWildcards, Resources.shellWordsPowerShellEscapeReplacement) : value;
|
|
73
73
|
const quoted = quote ?? (isPowerShell && (literal !== value || Resources.powerShellSpecial.test(value)) ? Resources.singleQuote : null);
|
|
74
74
|
if (Object.isNull(quoted))
|
|
75
|
-
return isPowerShell ? literal : `${!keepsHome && value.startsWith(Resources.homeWord) ? Resources.posixEscape :
|
|
75
|
+
return isPowerShell ? literal : `${!keepsHome && value.startsWith(Resources.homeWord) ? Resources.posixEscape : String.empty}${value.replace(Resources.posixSpecial, Resources.shellWordsPosixEscapeReplacement)}`;
|
|
76
76
|
const body = quoted === Resources.singleQuote
|
|
77
77
|
? literal.replaceAll(Resources.singleQuote, isPowerShell ? Resources.shellWordsPowerShellQuotedSingleQuote : Resources.shellWordsPosixQuotedSingleQuote)
|
|
78
78
|
: literal.replace(isPowerShell ? Resources.powerShellQuotedSpecial : Resources.posixQuotedSpecial, isPowerShell ? Resources.shellWordsPowerShellEscapeReplacement : Resources.shellWordsPosixEscapeReplacement);
|
|
79
|
-
return `${quoted}${body}${closesQuote ? quoted :
|
|
79
|
+
return `${quoted}${body}${closesQuote ? quoted : String.empty}`;
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -49,7 +49,7 @@ export class TerminalHistorySegment {
|
|
|
49
49
|
return bytes;
|
|
50
50
|
}
|
|
51
51
|
take() {
|
|
52
|
-
const buffer = Buffer.from(this.batch.join(
|
|
52
|
+
const buffer = Buffer.from(this.batch.join(String.empty), Resources.utf8Encoding);
|
|
53
53
|
this.discard();
|
|
54
54
|
return buffer;
|
|
55
55
|
}
|