@noldova/terminal 0.0.12 → 0.0.13

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 CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "id": "terminal",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "displayName": "Terminal",
5
5
  "description": "Runs shells in terminal panes, and lets AI agents run commands in them through permission requests.",
6
6
  "parts": ["runtime", "window"],
7
7
  "pseudoTerminals": true,
8
8
  "dependencies": {},
9
- "noldovaDesktop": ">=0.0.29 <0.1.0",
9
+ "noldovaDesktop": ">=0.0.30 <0.1.0",
10
10
  "contributes": {
11
11
  "methods": [
12
12
  "terminal.shells", "terminal.open", "terminal.close", "terminal.restart", "terminal.sessions", "terminal.attach", "terminal.input", "terminal.resize",
@@ -22,7 +22,7 @@
22
22
  ],
23
23
  "commands": ["terminal.new", "terminal.newWithShell", "terminal.toggle", "terminal.restartShell"],
24
24
  "menus": ["terminal.tabRow", "terminal.shellMenu"],
25
- "settings": ["terminal.defaultShell", "terminal.outputLimit", "terminal.fontSize", "terminal.suggestions", "terminal.commandColors", "terminal.completionList", "terminal.linkClick"],
25
+ "settings": ["terminal.defaultShell", "terminal.outputLimit", "terminal.fontSize", "terminal.suggestions", "terminal.commandColors", "terminal.completionList", "terminal.linkClick", "terminal.restoreTerminals"],
26
26
  "views": ["terminal.panel", "terminal.session"],
27
27
  "tools": ["terminal_list", "terminal_read", "terminal_open", "terminal_run", "terminal_write", "terminal_interrupt", "terminal_close"]
28
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noldova/terminal",
3
- "version": "0.0.12",
3
+ "version": "0.0.13",
4
4
  "description": "The terminal module for apps on Noldova Desktop: terminal panes over real shells, and agent tools that run commands through permission requests.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -37,18 +37,18 @@
37
37
  "registry": "https://registry.npmjs.org/"
38
38
  },
39
39
  "dependencies": {
40
- "@noldova/terminal.protocol": "0.0.12",
41
- "@noldova/terminal.window": "0.0.12",
40
+ "@noldova/terminal.protocol": "0.0.13",
41
+ "@noldova/terminal.window": "0.0.13",
42
42
  "@xterm/addon-serialize": "0.14.0",
43
43
  "@xterm/headless": "6.0.0",
44
44
  "node-pty": "1.2.0-beta.15"
45
45
  },
46
46
  "peerDependencies": {
47
- "@noldova/desktop.protocol": ">=0.0.29 <0.1.0",
48
- "@noldova/desktop.runtime": ">=0.0.29 <0.1.0",
47
+ "@noldova/desktop.protocol": ">=0.0.30 <0.1.0",
48
+ "@noldova/desktop.runtime": ">=0.0.30 <0.1.0",
49
49
  "@noldova/context.core": ">=0.0.18 <0.1.0",
50
50
  "@noldova/context.exceptions": ">=0.0.18 <0.1.0",
51
51
  "@noldova/context.json": ">=0.0.18 <0.1.0"
52
52
  },
53
- "gitHead": "78f6600e1848b0ee2bde8fb510f0df54ba5f0eec"
53
+ "gitHead": "84d04389daae0ffc8961880c1cbc8c11239c80f9"
54
54
  }
package/settings.json CHANGED
@@ -95,6 +95,17 @@
95
95
  "scopes": [],
96
96
  "page": "Terminal",
97
97
  "group": "Terminal"
98
+ },
99
+ {
100
+ "name": "terminal.restoreTerminals",
101
+ "title": "Restore terminals at start",
102
+ "description": "Whether a window opens again the terminals you left open when the app last closed, and their tabs after a reload.",
103
+ "type": { "kind": "Boolean" },
104
+ "default": true,
105
+ "locality": "Shared",
106
+ "scopes": [],
107
+ "page": "Terminal",
108
+ "group": "Terminal"
98
109
  }
99
110
  ]
100
111
  }
@@ -58,6 +58,33 @@ export { TerminalWindowException } from "@noldova/terminal.window";
58
58
  */
59
59
  export { StartFolderProvidedException } from "@noldova/terminal.window";
60
60
 
61
+ /**
62
+ * What New Terminal does in a window whose app opens terminals of its own, from `@noldova/terminal.window`.
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * import type { IWindowPartContext } from "@noldova/desktop.window";
67
+ * import { TerminalNew } from "@noldova/terminal/window";
68
+ *
69
+ * export function provideNew(context: IWindowPartContext, open: () => Promise<void>): () => void {
70
+ * return TerminalNew.provide(context, open);
71
+ * }
72
+ * ```
73
+ */
74
+ export { TerminalNew } from "@noldova/terminal.window";
75
+
76
+ /**
77
+ * Thrown when a window that already has a New Terminal provider is given another, from `@noldova/terminal.window`.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import { NewTerminalProvidedException } from "@noldova/terminal/window";
82
+ *
83
+ * console.log(new NewTerminalProvidedException().name);
84
+ * ```
85
+ */
86
+ export { NewTerminalProvidedException } from "@noldova/terminal.window";
87
+
61
88
  /**
62
89
  * What Toggle Terminal does in a window whose app shows a terminal of its own, from `@noldova/terminal.window`.
63
90
  *
package/src/api/window.js CHANGED
@@ -5,4 +5,4 @@
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
- export { EmbeddedRowsRefusedException, EmbeddedTerminal, LaunchArgumentRefusedException, LaunchedTab, LaunchedTerminal, LaunchFolderMissingException, LaunchPartInactiveException, LaunchRowsRefusedException, LaunchRowsWithoutTabException, LaunchTitleRefusedException, OwnersProvidedException, RunArgumentRefusedException, RunLinesRefusedException, RunPartInactiveException, RunShellKindsMissingException, StartFolderProvidedException, TerminalEnd, TerminalLaunch, TerminalLauncher, TerminalLaunchRefusedException, TerminalEndedException, TerminalFolderNotFollowedException, TerminalFolderRefusedException, TerminalNotActiveException, TerminalLine, TerminalListener, TerminalOwners, TerminalRun, TerminalRunBusy, TerminalRunEnd, TerminalRunNotFoundException, TerminalRunNotTypedException, TerminalRunOutcome, TerminalRunOutput, TerminalRunRefusedException, TerminalRunTarget, TerminalShellKind, TerminalStartFolder, TerminalTextRun, TerminalTextStyle, TerminalToggle, TerminalWindowException, TerminalWithoutTabException, ToggleProvidedException, windowPart } from "@noldova/terminal.window";
8
+ export { EmbeddedRowsRefusedException, EmbeddedTerminal, LaunchArgumentRefusedException, LaunchedTab, LaunchedTerminal, LaunchFolderMissingException, LaunchPartInactiveException, LaunchRowsRefusedException, LaunchRowsWithoutTabException, LaunchTitleRefusedException, NewTerminalProvidedException, OwnersProvidedException, RunArgumentRefusedException, RunLinesRefusedException, RunPartInactiveException, RunShellKindsMissingException, StartFolderProvidedException, TerminalEnd, TerminalLaunch, TerminalLauncher, TerminalLaunchRefusedException, TerminalEndedException, TerminalFolderNotFollowedException, TerminalFolderRefusedException, TerminalNotActiveException, TerminalLine, TerminalListener, TerminalNew, TerminalOwners, TerminalRun, TerminalRunBusy, TerminalRunEnd, TerminalRunNotFoundException, TerminalRunNotTypedException, TerminalRunOutcome, TerminalRunOutput, TerminalRunRefusedException, TerminalRunTarget, TerminalShellKind, TerminalStartFolder, TerminalTextRun, TerminalTextStyle, TerminalToggle, TerminalWindowException, TerminalWithoutTabException, ToggleProvidedException, windowPart } from "@noldova/terminal.window";
@@ -10,5 +10,6 @@ export const ShellFamily = {
10
10
  Zsh: "Zsh",
11
11
  PowerShell: "PowerShell",
12
12
  CommandPrompt: "CommandPrompt",
13
+ Wsl: "Wsl",
13
14
  Other: "Other"
14
15
  };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ export class ProgramCall {
9
+ file;
10
+ args;
11
+ constructor(file, args) {
12
+ this.file = file;
13
+ this.args = args;
14
+ }
15
+ }
package/src/resources.js CHANGED
@@ -64,6 +64,8 @@ export class Resources {
64
64
  static pathReset = "Path";
65
65
  static temporaryFolderProperty = "Temp=";
66
66
  static temporaryFolderReset = "Temp";
67
+ static homeProperty = "Home=";
68
+ static homeReset = "Home";
67
69
  static maximumPathValueLength = 19_456;
68
70
  static namesProperty = "Names=";
69
71
  static namesReset = "Names";
@@ -164,6 +166,7 @@ export class Resources {
164
166
  static loginArgument = "-l";
165
167
  static shellVariable = "SHELL";
166
168
  static pathVariable = "PATH";
169
+ static homeVariable = "HOME";
167
170
  static pathExtensionsVariable = "PATHEXT";
168
171
  static defaultPathExtensions = ".COM;.EXE;.BAT;.CMD";
169
172
  static windowsProgramExtension = /\.(?:com|exe|bat|cmd|ps1)$/u;
@@ -508,6 +511,8 @@ for ($index = 0; $index -lt $names.Count; $index++) {
508
511
  static wslIdPrefix = "wsl-";
509
512
  static wslPath = ["System32", "wsl.exe"];
510
513
  static wslDistributionArgument = "-d";
514
+ static wslExecArgument = "--exec";
515
+ static wslShareRoot = "\\\\wsl.localhost\\";
511
516
  static wslDockerPrefix = "docker-desktop";
512
517
  static wslDefaultFlag = "1";
513
518
  static wslOtherFlag = "0";
@@ -646,6 +651,24 @@ for ($index = 0; $index -lt $names.Count; $index++) {
646
651
  static commandHasControls = "The value must be one line, without control characters.";
647
652
  static noKeys = "The value must not be empty.";
648
653
  static bashExecutable = "bash";
654
+ static wslExecutable = "wsl";
655
+ static wslEnvironmentVariable = "WSLENV";
656
+ static wslEnvironmentSeparator = ":";
657
+ static wslPathFlag = "/p";
658
+ static wslStartShell = "/bin/sh";
659
+ static wslStartArgument = "-c";
660
+ static integrationFolderVariable = "NOLDOVA_TERMINAL_FOLDER";
661
+ static shellIntegrationWslStart = `f="$NOLDOVA_TERMINAL_FOLDER"
662
+ unset NOLDOVA_TERMINAL_FOLDER
663
+ s="$(getent passwd "$(id -un)" 2>/dev/null | cut -d: -f7)"
664
+ [ -n "$s" ] || s="\${SHELL:-/bin/sh}"
665
+ case "\${s##*/}" in
666
+ bash) if [ -r "$f/noldova.bash" ]; then exec "$s" --init-file "$f/noldova.bash" -i; fi ;;
667
+ zsh) if [ -r "$f/.zshenv" ]; then unset NOLDOVA_TERMINAL_LOGIN; ZDOTDIR="$f" exec "$s" -l; fi ;;
668
+ esac
669
+ if [ -n "\${NOLDOVA_TERMINAL_NOTE-}" ]; then printf '%s' "$NOLDOVA_TERMINAL_NOTE"; fi
670
+ unset NOLDOVA_TERMINAL_NONCE_FILE NOLDOVA_TERMINAL_LOGIN NOLDOVA_TERMINAL_NOTE
671
+ exec "$s" -l`;
649
672
  static zshExecutable = "zsh";
650
673
  static pwshExecutable = "pwsh";
651
674
  static windowsPowerShellExecutable = "powershell";
@@ -1273,6 +1296,12 @@ if [ -n "\${__noldova_nonce_read-}" ] && [ -z "\${__noldova_nonce-}" ]; then
1273
1296
  __noldova_capped_mark "$__noldova_temp" ${Resources.maximumPathValueLength} ${Resources.temporaryFolderProperty} ${Resources.temporaryFolderReset}
1274
1297
  fi
1275
1298
  fi
1299
+ # The distribution's home, once at the first prompt, in a WSL shell, so the terminal reads ~ in the distribution's own file system.
1300
+ if [ -n "\${WSL_DISTRO_NAME-}" ] && [ -z "\${__noldova_home+set}" ]; then
1301
+ __noldova_home="$HOME"
1302
+ builtin export -n __noldova_home
1303
+ __noldova_capped_mark "$__noldova_home" ${Resources.maximumPathValueLength} ${Resources.homeProperty} ${Resources.homeReset}
1304
+ fi
1276
1305
  # bash 5.3's compgen -V lists the names into a variable, with no subshell. An older bash lists them in a subshell, a few milliseconds on
1277
1306
  # Linux or macOS, but over 50 in Git Bash, whose fork is slow, so an older Git Bash sends no names and no command shows as missing there.
1278
1307
  # Functions starting with _, as bash-completion's hundreds are, are left out; the terminal never shows such a name as missing.
@@ -1752,6 +1781,12 @@ if [[ -n "\${__noldova_nonce_read-}" && -z "\${__noldova_nonce-}" ]]; then
1752
1781
  builtin typeset -g +x __noldova_path
1753
1782
  __noldova_capped_mark "$PATH" ${Resources.maximumPathValueLength} ${Resources.pathProperty} ${Resources.pathReset}
1754
1783
  fi
1784
+ # The distribution's home, once at the first prompt, in a WSL shell, so the terminal reads ~ in the distribution's own file system.
1785
+ if [[ -n "\${WSL_DISTRO_NAME-}" && -z "\${__noldova_home+set}" ]]; then
1786
+ __noldova_home="$HOME"
1787
+ builtin typeset -g +x __noldova_home
1788
+ __noldova_capped_mark "$HOME" ${Resources.maximumPathValueLength} ${Resources.homeProperty} ${Resources.homeReset}
1789
+ fi
1755
1790
  # The aliases, functions, builtins and keywords, apart by spaces, so the terminal can tell a typed command the shell wouldn't find.
1756
1791
  # Functions starting with _, as compinit's completion functions are, are left out; the terminal never shows such a name as missing. Each
1757
1792
  # suffix alias adds *.<suffix>, and autocd adds */, as a file with that suffix and a folder's name run too.
@@ -27,6 +27,7 @@ export class CommandTracker {
27
27
  path = null;
28
28
  isPathReset = false;
29
29
  temporaryFolder = null;
30
+ home = null;
30
31
  modulePath = null;
31
32
  isModulePathReset = false;
32
33
  names = null;
@@ -107,6 +108,10 @@ export class CommandTracker {
107
108
  this.temporaryFolder = mark.value.slice(Resources.temporaryFolderProperty.length);
108
109
  else if (mark.value === Resources.temporaryFolderReset)
109
110
  this.temporaryFolder = null;
111
+ else if (mark.value?.startsWith(Resources.homeProperty) === true)
112
+ this.home = mark.value.slice(Resources.homeProperty.length);
113
+ else if (mark.value === Resources.homeReset)
114
+ this.home = null;
110
115
  else if (mark.value?.startsWith(Resources.modulePathProperty) === true) {
111
116
  this.modulePath = mark.value.slice(Resources.modulePathProperty.length);
112
117
  this.isModulePathReset = false;
@@ -7,7 +7,7 @@
7
7
  */
8
8
  import "@noldova/context.core";
9
9
  import path from "node:path";
10
- import { Resources as ProtocolResources, TerminalCompletion, TerminalCompletionItem, TerminalCompletionKind, TerminalMissingCommands, TerminalShellKind } from "@noldova/terminal.protocol";
10
+ import { Resources as ProtocolResources, TerminalCompletion, TerminalCompletionItem, TerminalCompletionKind, TerminalMissingCommands } from "@noldova/terminal.protocol";
11
11
  import { CommandFailedException } from "../exceptions/command-failed.exception.js";
12
12
  import { CommandListing } from "../models/command-listing.js";
13
13
  import { CompletionCandidate } from "../models/completion-candidate.js";
@@ -41,26 +41,26 @@ export class CompletionSource {
41
41
  this.adapters = new ShellAdapters(this.isWindows);
42
42
  this.shared = new SharedReads(fileSystem);
43
43
  }
44
- async completeAsync(key, kind, line, cursor, folder, environment, shellNames, shellBuiltins) {
45
- const shell = this.adapters.of(kind);
44
+ async completeAsync(key, target, line, cursor, folder, environment, shellNames, shellBuiltins) {
45
+ const shell = this.adapters.of(target);
46
46
  if (Object.isNull(shell) || this.stuck.includes(key))
47
47
  return new TerminalCompletion(cursor, []);
48
48
  const builtins = shell.listBuiltins(shellNames, shellBuiltins);
49
49
  return this.readAsync(key, t => this.completeLineAsync(t, shell, builtins, line.slice(0, cursor), folder, environment));
50
50
  }
51
- adapterOf(kind) {
52
- return this.adapters.of(kind);
51
+ adapterOf(target) {
52
+ return this.adapters.of(target);
53
53
  }
54
- toLocalFolder(folder, kind, environment) {
55
- const shell = this.adapters.of(kind);
54
+ toLocalFolder(folder, target, environment) {
55
+ const shell = this.adapters.of(target);
56
56
  return Object.isNull(shell) ? folder : shell.toLocalPath(folder, this.readVariable(environment, Resources.temporaryFolderVariable) ?? null);
57
57
  }
58
- followsCommand(kind, line, cursor) {
59
- const shell = this.adapters.of(kind);
58
+ followsCommand(target, line, cursor) {
59
+ const shell = this.adapters.of(target);
60
60
  return !Object.isNull(shell) && shell.readWords(line.slice(0, cursor)).words.length > 0;
61
61
  }
62
- addOptions(completion, kind, line, cursor, options) {
63
- const ignoresCase = this.isWindows || this.adapters.of(kind)?.ignoresCase === true;
62
+ addOptions(completion, target, line, cursor, options) {
63
+ const ignoresCase = this.adapters.of(target)?.ignoresCase === true;
64
64
  const toKey = (text) => ignoresCase ? text.toLowerCase() : text;
65
65
  const prefix = toKey(line.slice(completion.replaceFrom, cursor));
66
66
  const labels = new Set(completion.items.map(t => t.label));
@@ -73,24 +73,24 @@ export class CompletionSource {
73
73
  const items = [...completion.items, ...added].sort((a, b) => a.label.localeCompare(b.label, Resources.sortLocale));
74
74
  return new TerminalCompletion(completion.replaceFrom, items.slice(0, ProtocolResources.maximumCompletionItems));
75
75
  }
76
- async findMissingAsync(key, shell, prompt, kind, folder, names, shellNames, environment) {
77
- const adapter = this.adapters.of(kind);
76
+ async findMissingAsync(key, shell, prompt, target, folder, names, shellNames, environment) {
77
+ const adapter = this.adapters.of(target);
78
78
  if (Object.isNull(adapter) || adapter.looksUpMissing || Object.isNull(shellNames) || this.stuck.includes(key))
79
79
  return new TerminalMissingCommands([]);
80
80
  const takesBareNames = adapter.takesBareNames;
81
- const search = JSON.stringify([kind, this.readVariable(environment, Resources.pathVariable),
81
+ const search = JSON.stringify([target.kind, target.name, this.readVariable(environment, Resources.pathVariable),
82
82
  this.readVariable(environment, Resources.pathExtensionsVariable)]);
83
83
  const last = this.listed.get(shell);
84
84
  const listed = !Object.isUndefined(last) && last.prompt === prompt && last.search === search ? last.commands : null;
85
85
  return this.readAsync(key, async (reads) => {
86
- const commands = listed ?? (await this.listCommandsAsync(reads, [], environment, takesBareNames)).map(t => t.value);
86
+ const commands = listed ?? (await this.listCommandsAsync(reads, adapter, [], environment, takesBareNames)).map(t => t.value);
87
87
  if (reads.wasCutShort)
88
88
  return new TerminalMissingCommands([]);
89
89
  this.listed.set(shell, new CommandListing(prompt, search, commands));
90
90
  const found = [...shellNames, ...commands];
91
- const known = new Set(this.isWindows ? found.map(t => t.toLowerCase()) : found);
92
- const unknown = names.filter(t => !this.isPath(t) && !t.startsWith(Resources.helperNamePrefix)
93
- && !known.has(this.toCommandName(t)) && !this.hasSuffixAlias(t, shellNames));
91
+ const known = new Set(adapter.takesWindowsNames ? found.map(t => t.toLowerCase()) : found);
92
+ const unknown = names.filter(t => !this.isPath(adapter, t) && !t.startsWith(Resources.helperNamePrefix)
93
+ && !known.has(this.toCommandName(adapter, t)) && !this.hasSuffixAlias(t, shellNames));
94
94
  const missing = unknown.length > 0 && shellNames.has(Resources.autocdName)
95
95
  ? await this.dropFoldersAsync(reads, adapter, folder, environment, unknown) : unknown;
96
96
  return new TerminalMissingCommands(reads.wasCutShort ? [] : missing);
@@ -116,7 +116,7 @@ export class CompletionSource {
116
116
  const answers = !Object.isUndefined(last) && last.shellNames === shellNames && last.search === search ? last.answers : new Map();
117
117
  this.looked.set(shell, new PowerShellLookup(shellNames, search, answers));
118
118
  const known = new Set([...shellNames].map(t => t.toLowerCase()));
119
- const asked = [...new Set(names)].filter(t => !this.isPath(t) && Resources.powerShellLookupNamePattern.test(t)
119
+ const asked = [...new Set(names)].filter(t => !this.isPath(null, t) && Resources.powerShellLookupNamePattern.test(t)
120
120
  && !known.has(t.toLowerCase()) && !known.has(`${Resources.powerShellImplicitVerb}${t}`.toLowerCase()));
121
121
  const unasked = asked.filter(t => !answers.has(t));
122
122
  if (unasked.length > 0 && !this.lookups.has(shell)) {
@@ -150,8 +150,8 @@ export class CompletionSource {
150
150
  if (Object.isNull(workFolder))
151
151
  return names;
152
152
  const folders = new Set((await reads.readEntriesAsync(workFolder)).filter(t => t.isFolder)
153
- .map(t => this.isWindows ? t.name.toLowerCase() : t.name));
154
- return names.filter(t => !folders.has(this.isWindows ? t.toLowerCase() : t));
153
+ .map(t => shell.takesWindowsNames ? t.name.toLowerCase() : t.name));
154
+ return names.filter(t => !folders.has(shell.takesWindowsNames ? t.toLowerCase() : t));
155
155
  }
156
156
  async readAsync(key, list) {
157
157
  const reads = new BoundedReads(this.shared, Resources.completionReadMilliseconds);
@@ -172,10 +172,10 @@ export class CompletionSource {
172
172
  const shellLine = escapesWildcards
173
173
  ? new ShellLine(typed.words, typed.start, typed.value.replace(Resources.powerShellEscapedWildcards, Resources.completionSourceEscapedWildcardReplacement), typed.quote, typed.startsQuoted)
174
174
  : typed;
175
- const ignoresCase = this.isWindows || shell.ignoresCase;
175
+ const ignoresCase = shell.ignoresCase;
176
176
  const prefix = ignoresCase ? shellLine.value.toLowerCase() : shellLine.value;
177
177
  const expandsHome = shell.expandsHome(shellLine.startsQuoted);
178
- const keepsHome = expandsHome && this.isHome(shellLine.value);
178
+ const keepsHome = expandsHome && this.isHome(shell, shellLine.value);
179
179
  const candidates = (await this.listAsync(reads, shell, builtins, shellLine, folder, environment, expandsHome))
180
180
  .filter(t => (ignoresCase ? t.value.toLowerCase() : t.value).startsWith(prefix));
181
181
  const items = [...new Map(candidates.map(t => [t.value, t])).values()]
@@ -189,45 +189,46 @@ export class CompletionSource {
189
189
  return new TerminalCompletion(shellLine.start, items.slice(0, ProtocolResources.maximumCompletionItems));
190
190
  }
191
191
  listAsync(reads, shell, builtins, shellLine, folder, environment, expandsHome) {
192
- const words = shellLine.words.map(t => this.toCommandName(t));
193
- if (words.length === 0 && !this.isPath(shellLine.value))
194
- return this.listCommandsAsync(reads, builtins, environment);
192
+ const words = shellLine.words.map(t => this.toCommandName(shell, t));
193
+ if (words.length === 0 && !this.isPath(shell, shellLine.value))
194
+ return this.listCommandsAsync(reads, shell, builtins, environment);
195
195
  const temporaryFolder = this.readVariable(environment, Resources.temporaryFolderVariable) ?? null;
196
196
  const workFolder = shell.toLocalPath(folder, temporaryFolder);
197
197
  if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.gitCommand && Resources.gitBranchCommands.some(t => shellLine.words[1] === t))
198
- return this.listBranchesAsync(reads, workFolder, environment);
198
+ return this.listBranchesAsync(reads, shell, workFolder, environment);
199
199
  if (!Object.isNull(workFolder) && words.length === Resources.subcommandWordCount && words[0] === Resources.npmCommand && Resources.npmRunCommands.some(t => shellLine.words[1] === t))
200
200
  return this.listScriptsAsync(reads, workFolder);
201
- const paths = this.listPathsAsync(reads, shell, shellLine.value, workFolder, expandsHome, temporaryFolder);
201
+ const home = this.homeOf(shell, environment);
202
+ const paths = this.listPathsAsync(reads, shell, shellLine.value, workFolder, expandsHome ? home : null, temporaryFolder);
202
203
  const command = words.length === 1 ? words[0] : undefined;
203
- if (Object.isUndefined(command) || this.isPath(shellLine.value))
204
+ if (Object.isUndefined(command) || this.isPath(shell, shellLine.value))
204
205
  return paths;
205
- return this.listToolWordsAsync(reads, command, workFolder, paths);
206
+ return this.listToolWordsAsync(reads, shell, command, workFolder, paths);
206
207
  }
207
- async listToolWordsAsync(reads, command, workFolder, paths) {
208
+ async listToolWordsAsync(reads, shell, command, workFolder, paths) {
208
209
  const tool = Resources.toolCommands.find(t => t.name === command);
209
210
  if (!Object.isUndefined(tool))
210
211
  return [...tool.words.map(t => new CompletionCandidate(t.name, t.name, TerminalCompletionKind.Command, true, t.description)), ...(await paths).map(t => t.ranked(1))];
211
212
  if (command === Resources.nodeCommand)
212
213
  return (await paths).map(t => t.kind === TerminalCompletionKind.File && Resources.nodeScriptExtensions.includes(this.paths.extname(t.label).toLowerCase()) ? t : t.ranked(1));
213
214
  if (command === Resources.npxCommand && !Object.isNull(workFolder))
214
- return [...await this.listPackageBinsAsync(reads, workFolder), ...(await paths).map(t => t.ranked(1))];
215
+ return [...await this.listPackageBinsAsync(reads, shell, workFolder), ...(await paths).map(t => t.ranked(1))];
215
216
  return paths;
216
217
  }
217
- async listPackageBinsAsync(reads, folder) {
218
+ async listPackageBinsAsync(reads, shell, folder) {
218
219
  let current = folder;
219
220
  for (;;) {
220
221
  const entries = await reads.readEntriesAsync(this.paths.join(current, ...Resources.packageBinFolder));
221
- const names = [...new Set(entries.filter(t => !t.isFolder).map(t => this.isWindows ? t.name.replace(Resources.packageBinExtension, "") : t.name))];
222
+ const names = [...new Set(entries.filter(t => !t.isFolder).map(t => shell.takesWindowsNames ? t.name.replace(Resources.packageBinExtension, "") : t.name))];
222
223
  if (names.length > 0 || this.paths.dirname(current) === current)
223
224
  return names.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Command, true));
224
225
  current = this.paths.dirname(current);
225
226
  }
226
227
  }
227
- async listPathsAsync(reads, shell, value, workFolder, expandsHome, temporaryFolder) {
228
- const end = Math.max(value.lastIndexOf(Resources.posixSeparator), this.isWindows ? value.lastIndexOf(Resources.windowsSeparator) : -1);
228
+ async listPathsAsync(reads, shell, value, workFolder, home, temporaryFolder) {
229
+ const end = Math.max(value.lastIndexOf(Resources.posixSeparator), shell.takesWindowsNames ? value.lastIndexOf(Resources.windowsSeparator) : -1);
229
230
  const typedFolder = value.slice(0, end + 1);
230
- const folder = Object.isNull(workFolder) ? null : this.toFolder(shell, typedFolder, workFolder, expandsHome, temporaryFolder);
231
+ const folder = Object.isNull(workFolder) ? null : this.toFolder(shell, typedFolder, workFolder, home, temporaryFolder);
231
232
  if (Object.isNull(folder))
232
233
  return [];
233
234
  const separator = end >= 0 ? value.charAt(end) : shell.separator;
@@ -238,12 +239,12 @@ export class CompletionSource {
238
239
  ? new CompletionCandidate(`${typedFolder}${t.name}${separator}`, `${t.name}${separator}`, TerminalCompletionKind.Folder, false)
239
240
  : new CompletionCandidate(`${typedFolder}${t.name}`, t.name, TerminalCompletionKind.File, true));
240
241
  }
241
- async listCommandsAsync(reads, builtins, environment, takesBareNames = false) {
242
- const extensions = this.isWindows
242
+ async listCommandsAsync(reads, shell, builtins, environment, takesBareNames = false) {
243
+ const extensions = shell.takesWindowsNames
243
244
  ? (this.readVariable(environment, Resources.pathExtensionsVariable) ?? Resources.defaultPathExtensions).toLowerCase()
244
245
  .split(path.win32.delimiter).filter(t => t !== "")
245
246
  : null;
246
- const entries = await Promise.all(this.searchFolders(environment).map(t => reads.readEntriesAsync(t)));
247
+ const entries = await Promise.all(this.searchFolders(shell, environment).map(t => reads.readEntriesAsync(t)));
247
248
  const names = [...builtins];
248
249
  for (const entry of entries.flat()) {
249
250
  const extension = this.paths.extname(entry.name).toLowerCase();
@@ -252,13 +253,14 @@ export class CompletionSource {
252
253
  }
253
254
  return names.map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Command, true));
254
255
  }
255
- async listBranchesAsync(reads, folder, environment) {
256
- const git = await this.findProgramAsync(reads, this.isWindows ? Resources.gitExecutableFile : Resources.gitCommand, environment);
256
+ async listBranchesAsync(reads, shell, folder, environment) {
257
+ const git = await this.findProgramAsync(reads, shell, shell.takesWindowsNames ? Resources.gitExecutableFile : Resources.gitCommand, environment);
257
258
  if (Object.isNull(git))
258
259
  return [];
260
+ const call = shell.toProgramCall(git, [Resources.completionSourceGitFolderArgument, folder, ...Resources.gitBranchArguments]);
259
261
  let output;
260
262
  try {
261
- output = await this.runner.runAsync(git, [Resources.completionSourceGitFolderArgument, folder, ...Resources.gitBranchArguments], Resources.completionCommandMilliseconds);
263
+ output = await this.runner.runAsync(call.file, call.args, Resources.completionCommandMilliseconds);
262
264
  }
263
265
  catch (error) {
264
266
  if (error instanceof CommandFailedException)
@@ -297,16 +299,23 @@ export class CompletionSource {
297
299
  return [];
298
300
  return Object.keys(scripts).map(t => new CompletionCandidate(t, t, TerminalCompletionKind.Script, true));
299
301
  }
300
- async findProgramAsync(reads, name, environment) {
301
- for (const folder of this.searchFolders(environment)) {
302
+ async findProgramAsync(reads, shell, name, environment) {
303
+ for (const folder of this.searchFolders(shell, environment)) {
302
304
  const file = this.paths.join(folder, name);
303
305
  if (await reads.isProgramAsync(file))
304
306
  return file;
305
307
  }
306
308
  return null;
307
309
  }
308
- searchFolders(environment) {
309
- return [...new Set((this.readVariable(environment, Resources.pathVariable) ?? "").split(this.paths.delimiter).filter(t => this.paths.isAbsolute(t)))];
310
+ searchFolders(shell, environment) {
311
+ return [...new Set(shell.readSearchFolders(this.readVariable(environment, Resources.pathVariable) ?? ""))];
312
+ }
313
+ homeOf(shell, environment) {
314
+ if (shell.takesWindowsNames)
315
+ return this.homeFolder;
316
+ const home = this.readVariable(environment, Resources.homeVariable);
317
+ const folder = !Object.isUndefined(home) && path.posix.isAbsolute(home) ? home : this.homeFolder;
318
+ return path.posix.isAbsolute(folder) ? shell.toLocalPath(folder, null) : null;
310
319
  }
311
320
  async toLongModulePathsAsync(variables) {
312
321
  const modulePath = variables[Resources.modulePathVariable];
@@ -325,19 +334,19 @@ export class CompletionSource {
325
334
  readVariable(environment, name) {
326
335
  return this.isWindows ? Object.entries(environment).find(([t]) => t.toUpperCase() === name)?.[1] : environment[name];
327
336
  }
328
- toFolder(shell, typedFolder, workFolder, expandsHome, temporaryFolder) {
329
- const folder = expandsHome && this.isHome(typedFolder) ? this.paths.join(this.homeFolder, typedFolder.slice(Resources.homePrefix.length)) : shell.toLocalPath(typedFolder, temporaryFolder);
337
+ toFolder(shell, typedFolder, workFolder, home, temporaryFolder) {
338
+ const folder = !Object.isNull(home) && this.isHome(shell, typedFolder) ? this.paths.join(home, typedFolder.slice(Resources.homePrefix.length)) : shell.toLocalPath(typedFolder, temporaryFolder);
330
339
  return Object.isNull(folder) ? null : this.paths.resolve(workFolder, folder);
331
340
  }
332
- toCommandName(word) {
333
- const name = this.paths.basename(word);
334
- return this.isWindows ? name.toLowerCase().replace(Resources.windowsProgramExtension, "") : name;
341
+ toCommandName(shell, word) {
342
+ const name = (shell.takesWindowsNames ? path.win32 : path.posix).basename(word);
343
+ return shell.takesWindowsNames ? name.toLowerCase().replace(Resources.windowsProgramExtension, "") : name;
335
344
  }
336
- isHome(value) {
337
- return value.startsWith(Resources.homePrefix) || (this.isWindows && value.startsWith(Resources.windowsHomePrefix));
345
+ isHome(shell, value) {
346
+ return value.startsWith(Resources.homePrefix) || (shell.takesWindowsNames && value.startsWith(Resources.windowsHomePrefix));
338
347
  }
339
- isPath(value) {
340
- return value.includes(Resources.posixSeparator) || (this.isWindows && value.includes(Resources.windowsSeparator))
348
+ isPath(shell, value) {
349
+ return value.includes(Resources.posixSeparator) || ((shell?.takesWindowsNames ?? this.isWindows) && value.includes(Resources.windowsSeparator))
341
350
  || value.startsWith(Resources.hiddenPrefix) || value.startsWith(Resources.homeWord);
342
351
  }
343
352
  }
@@ -7,6 +7,7 @@
7
7
  */
8
8
  import "@noldova/context.core";
9
9
  import path from "node:path";
10
+ import { ProgramCall } from "../models/program-call.js";
10
11
  import { Resources } from "../resources.js";
11
12
  import { ShellWords } from "./shell-words.js";
12
13
  export class PosixShellAdapter {
@@ -15,13 +16,17 @@ export class PosixShellAdapter {
15
16
  takesBareNames;
16
17
  optionsKeys;
17
18
  folderKeys;
19
+ takesWindowsNames;
18
20
  looksUpMissing = false;
19
21
  isGitBash;
22
+ paths;
20
23
  constructor(isWindows, optionsKeys, folderKeys, isBash) {
21
24
  this.ignoresCase = isWindows;
22
25
  this.optionsKeys = optionsKeys;
23
26
  this.folderKeys = folderKeys;
24
27
  this.isGitBash = isWindows && isBash;
28
+ this.takesWindowsNames = isWindows;
29
+ this.paths = isWindows ? path.win32 : path.posix;
25
30
  this.takesBareNames = this.isGitBash;
26
31
  }
27
32
  readWords(line) {
@@ -51,4 +56,10 @@ export class PosixShellAdapter {
51
56
  return null;
52
57
  return Resources.formatCompletionSourceWindowsDrivePath(value.charAt(1).toUpperCase(), value.slice(Resources.completionSourceGitBashDrivePrefixLength).replaceAll(Resources.posixSeparator, Resources.windowsSeparator));
53
58
  }
59
+ readSearchFolders(value) {
60
+ return value.split(this.paths.delimiter).filter(t => this.paths.isAbsolute(t));
61
+ }
62
+ toProgramCall(file, args) {
63
+ return new ProgramCall(file, args);
64
+ }
54
65
  }
@@ -6,6 +6,8 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
  import "@noldova/context.core";
9
+ import path from "node:path";
10
+ import { ProgramCall } from "../models/program-call.js";
9
11
  import { Resources } from "../resources.js";
10
12
  import { PowerShellBinding } from "./powershell-binding.js";
11
13
  import { ShellWords } from "./shell-words.js";
@@ -15,11 +17,15 @@ export class PowerShellShellAdapter {
15
17
  takesBareNames = false;
16
18
  optionsKeys = Resources.powerShellOptionsKeys;
17
19
  folderKeys = Resources.powerShellFolderKeys;
20
+ takesWindowsNames;
18
21
  looksUpMissing = true;
19
22
  binding;
23
+ paths;
20
24
  constructor(isWindows) {
21
25
  this.separator = isWindows ? Resources.windowsSeparator : Resources.posixSeparator;
22
26
  this.binding = new PowerShellBinding(isWindows);
27
+ this.takesWindowsNames = isWindows;
28
+ this.paths = isWindows ? path.win32 : path.posix;
23
29
  }
24
30
  readWords(line) {
25
31
  return ShellWords.read(line, true);
@@ -39,4 +45,10 @@ export class PowerShellShellAdapter {
39
45
  toLocalPath(value) {
40
46
  return value;
41
47
  }
48
+ readSearchFolders(value) {
49
+ return value.split(this.paths.delimiter).filter(t => this.paths.isAbsolute(t));
50
+ }
51
+ toProgramCall(file, args) {
52
+ return new ProgramCall(file, args);
53
+ }
42
54
  }
@@ -10,8 +10,10 @@ import { TerminalShellKind } from "@noldova/terminal.protocol";
10
10
  import { Resources } from "../resources.js";
11
11
  import { PosixShellAdapter } from "./posix-shell-adapter.js";
12
12
  import { PowerShellShellAdapter } from "./powershell-shell-adapter.js";
13
+ import { WslShellAdapter } from "./wsl-shell-adapter.js";
13
14
  export class ShellAdapters {
14
15
  adapters;
16
+ distributions = new Map();
15
17
  constructor(isWindows) {
16
18
  this.adapters = new Map([
17
19
  [TerminalShellKind.PowerShell, new PowerShellShellAdapter(isWindows)],
@@ -19,7 +21,12 @@ export class ShellAdapters {
19
21
  [TerminalShellKind.Zsh, new PosixShellAdapter(isWindows, Resources.zshOptionsKeys, Resources.zshFolderKeys, false)]
20
22
  ]);
21
23
  }
22
- of(kind) {
23
- return this.adapters.get(kind) ?? null;
24
+ of(shell) {
25
+ if (shell.kind !== TerminalShellKind.Wsl)
26
+ return this.adapters.get(shell.kind) ?? null;
27
+ const key = JSON.stringify([shell.file, shell.name]);
28
+ const adapter = this.distributions.get(key) ?? new WslShellAdapter(shell.file, shell.name);
29
+ this.distributions.set(key, adapter);
30
+ return adapter;
24
31
  }
25
32
  }
@@ -97,6 +97,15 @@ export class ShellIntegration {
97
97
  if (Object.isNull(folder) || Object.isNull(nonceFile))
98
98
  return ShellIntegration.toPlainLaunch(shell, family);
99
99
  const noteVariables = Object.isNull(note) ? {} : { [Resources.noteVariable]: note };
100
+ if (family === ShellFamily.Wsl)
101
+ return new ShellLaunch(shell.file, [...shell.args, Resources.wslExecArgument, Resources.wslStartShell, Resources.wslStartArgument,
102
+ Resources.shellIntegrationWslStart], {
103
+ [Resources.nonceFileVariable]: nonceFile,
104
+ [Resources.integrationFolderVariable]: folder,
105
+ [Resources.loginVariable]: Resources.shellIntegrationLoginValue,
106
+ ...noteVariables,
107
+ [Resources.wslEnvironmentVariable]: ShellIntegration.toWslEnvironment(environment, !Object.isNull(note))
108
+ }, nonce, nonceFile, !Object.isNull(note));
100
109
  if (family === ShellFamily.PowerShell)
101
110
  return new ShellLaunch(shell.file, [...shell.args, ...Resources.powerShellIntegrationArguments, ShellIntegration.encode([Resources.shellIntegrationPowerShellNonce, Resources.shellIntegrationPowerShellNote, Resources.shellIntegrationPowerShellProfiles, shell.startCommand,
102
111
  Resources.shellIntegrationPowerShellScript].filter(t => !Object.isNull(t)).join(Resources.lineFeed))], {
@@ -210,6 +219,8 @@ export class ShellIntegration {
210
219
  return ShellFamily.Zsh;
211
220
  case Resources.cmdExecutable:
212
221
  return ShellFamily.CommandPrompt;
222
+ case Resources.wslExecutable:
223
+ return ShellFamily.Wsl;
213
224
  case Resources.pwshExecutable:
214
225
  case Resources.windowsPowerShellExecutable:
215
226
  return ShellFamily.PowerShell;
@@ -217,6 +228,12 @@ export class ShellIntegration {
217
228
  return ShellFamily.Other;
218
229
  }
219
230
  }
231
+ static toWslEnvironment(environment, hasNote) {
232
+ const passed = Object.entries(environment).find(([t]) => t.toUpperCase() === Resources.wslEnvironmentVariable)?.[1];
233
+ return [...Object.isUndefined(passed) || passed === "" ? [] : [passed], `${Resources.nonceFileVariable}${Resources.wslPathFlag}`,
234
+ `${Resources.integrationFolderVariable}${Resources.wslPathFlag}`, Resources.loginVariable, ...hasNote ? [Resources.noteVariable] : []]
235
+ .join(Resources.wslEnvironmentSeparator);
236
+ }
220
237
  static encode(script) {
221
238
  return Buffer.from(script, Resources.utf16Encoding).toString(Resources.base64Encoding);
222
239
  }
@@ -298,7 +298,7 @@ export class TerminalHost {
298
298
  },
299
299
  onTitleChanged: t => publish(this.events.titleChanged, t.toJson()),
300
300
  onCwdChanged: t => {
301
- if (isKept && terminal.countsFolderReport(t.cwd))
301
+ if (isKept && this.isAbsolute(t.cwd) && terminal.countsFolderReport(t.cwd))
302
302
  this.saved.moveTo(t.sessionId, t.cwd);
303
303
  publish(this.events.cwdChanged, t.toJson());
304
304
  },
@@ -825,7 +825,7 @@ export class TerminalHost {
825
825
  const cwd = terminal.session.cwd;
826
826
  if (Object.isNull(cwd))
827
827
  return terminal.folder;
828
- const local = this.completions.toLocalFolder(cwd, terminal.shell.kind, this.readCompletionEnvironment(terminal));
828
+ const local = this.completions.toLocalFolder(cwd, terminal.shell, this.readCompletionEnvironment(terminal));
829
829
  if (Object.isNull(local))
830
830
  return null;
831
831
  return this.isAbsolute(local) ? local : terminal.folder;
@@ -867,25 +867,25 @@ export class TerminalHost {
867
867
  }
868
868
  async completeAsync(params, client) {
869
869
  const terminal = this.findHosted(params.sessionId, client);
870
- const keys = params.asksShell && this.completions.followsCommand(terminal.shell.kind, params.line, params.cursor)
871
- ? this.completions.adapterOf(terminal.shell.kind)?.optionsKeys ?? undefined : undefined;
870
+ const keys = params.asksShell && this.completions.followsCommand(terminal.shell, params.line, params.cursor)
871
+ ? this.completions.adapterOf(terminal.shell)?.optionsKeys ?? undefined : undefined;
872
872
  const [completion, reply] = await Promise.all([
873
- this.completions.completeAsync(params.sessionId, terminal.shell.kind, params.line, params.cursor, terminal.session.cwd ?? terminal.folder, this.readCompletionEnvironment(terminal), terminal.session.shellNames, terminal.session.shellBuiltins),
873
+ this.completions.completeAsync(params.sessionId, terminal.shell, params.line, params.cursor, terminal.session.cwd ?? terminal.folder, this.readCompletionEnvironment(terminal), terminal.session.shellNames, terminal.session.shellBuiltins),
874
874
  Object.isUndefined(keys) ? Promise.resolve(ShellOptionsReply.none) : terminal.session.askOptionsAsync(keys)
875
875
  ]);
876
876
  if (reply.isTimedOut)
877
877
  return new TerminalCompletion(params.cursor, [], true);
878
878
  return Object.isNull(reply.options) ? completion
879
- : this.completions.addOptions(completion, terminal.shell.kind, params.line, params.cursor, reply.options);
879
+ : this.completions.addOptions(completion, terminal.shell, params.line, params.cursor, reply.options);
880
880
  }
881
881
  async findCommandsAsync(params, client) {
882
882
  const terminal = this.findHosted(params.sessionId, client);
883
883
  const shellNames = terminal.session.isShellPathReset || terminal.session.isShellModulePathReset ? null
884
884
  : terminal.session.shellNames;
885
885
  const environment = this.readCompletionEnvironment(terminal);
886
- return this.completions.adapterOf(terminal.shell.kind)?.looksUpMissing === true
886
+ return this.completions.adapterOf(terminal.shell)?.looksUpMissing === true
887
887
  ? this.completions.findMissingPowerShellAsync(terminal.session.commands, terminal.shell.file, params.names, shellNames, environment)
888
- : this.completions.findMissingAsync(params.sessionId, terminal.session.commands, terminal.session.prompts, terminal.shell.kind, terminal.session.cwd ?? terminal.folder, params.names, shellNames, environment);
888
+ : this.completions.findMissingAsync(params.sessionId, terminal.session.commands, terminal.session.prompts, terminal.shell, terminal.session.cwd ?? terminal.folder, params.names, shellNames, environment);
889
889
  }
890
890
  async describeAsync(params, client) {
891
891
  const terminal = this.findHosted(params.sessionId, client);
@@ -900,6 +900,8 @@ export class TerminalHost {
900
900
  const temporaryFolder = terminal.session.shellTemporaryFolder ?? terminal.startTemporaryFolder;
901
901
  if (!Object.isNull(temporaryFolder))
902
902
  replaced[Resources.temporaryFolderVariable] = temporaryFolder;
903
+ if (!Object.isNull(terminal.session.shellHome))
904
+ replaced[Resources.homeVariable] = terminal.session.shellHome;
903
905
  const keys = new Set(Object.keys(replaced).map(t => this.toVariableKey(t)));
904
906
  return this.withVariables(TerminalHost.toTerminalEnvironment(this.environment.read()), {
905
907
  ...Object.fromEntries(Object.entries(terminal.environment ?? {}).filter(([t]) => !keys.has(this.toVariableKey(t)))),
@@ -1020,7 +1022,7 @@ export class TerminalHost {
1020
1022
  return new TerminalFolderChanged(null, true);
1021
1023
  if (!Object.isNull(terminal.pendingCommand) || !Object.isNull(session.commands.runningCommand))
1022
1024
  return new TerminalFolderChanged(null, true, TerminalRunOutcome.Busy);
1023
- const folderKeys = session.commands.hasFolderBinding ? this.completions.adapterOf(terminal.shell.kind)?.folderKeys ?? null : null;
1025
+ const folderKeys = session.commands.hasFolderBinding ? this.completions.adapterOf(terminal.shell)?.folderKeys ?? null : null;
1024
1026
  const before = session.cwd;
1025
1027
  const outcome = await this.typeCommandAsync(terminal, Object.isNull(folderKeys) ? line : params.folder, false, false, () => TerminalHost.readMoveRefusal(terminal), folderKeys);
1026
1028
  if (outcome === TerminalRunOutcome.NoShell)
@@ -1127,7 +1129,7 @@ export class TerminalHost {
1127
1129
  throw new HostEndedException();
1128
1130
  }
1129
1131
  async spawnFromAsync(base, file, args, folder, size, environment, inheritCursor) {
1130
- const process = await this.spawner.spawnAsync(file, args, folder, size.columns, size.rows, { ...base, ...environment }, inheritCursor);
1132
+ const process = await this.spawner.spawnAsync(file, args, folder, size.columns, size.rows, this.withVariables(base, environment), inheritCursor);
1131
1133
  if (this.hasEnded) {
1132
1134
  if (!await process.endAsync())
1133
1135
  this.log.write(Resources.formatLateShellLeftRunning(process.pid));
@@ -110,6 +110,9 @@ export class TerminalSession {
110
110
  get shellTemporaryFolder() {
111
111
  return this.commands.temporaryFolder;
112
112
  }
113
+ get shellHome() {
114
+ return this.commands.home;
115
+ }
113
116
  get shellModulePath() {
114
117
  return this.commands.modulePath;
115
118
  }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * @license
3
+ * Copyright (c) Noldova.
4
+ *
5
+ * This source code is licensed under the license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ import path from "node:path";
9
+ import { ProgramCall } from "../models/program-call.js";
10
+ import { Resources } from "../resources.js";
11
+ import { PosixShellAdapter } from "./posix-shell-adapter.js";
12
+ export class WslShellAdapter {
13
+ ignoresCase = false;
14
+ separator = Resources.posixSeparator;
15
+ takesBareNames = false;
16
+ optionsKeys = null;
17
+ folderKeys = null;
18
+ looksUpMissing = false;
19
+ takesWindowsNames = false;
20
+ posix = new PosixShellAdapter(false, null, null, false);
21
+ launcher;
22
+ distribution;
23
+ share;
24
+ constructor(launcher, distribution) {
25
+ this.launcher = launcher;
26
+ this.distribution = distribution;
27
+ this.share = `${Resources.wslShareRoot}${distribution}`;
28
+ }
29
+ readWords(line) {
30
+ return this.posix.readWords(line);
31
+ }
32
+ writeWord(value, quote, closesQuote, escapesWildcards, keepsHome) {
33
+ return this.posix.writeWord(value, quote, closesQuote, escapesWildcards, keepsHome);
34
+ }
35
+ escapesWildcards() {
36
+ return false;
37
+ }
38
+ expandsHome(startsQuoted) {
39
+ return this.posix.expandsHome(startsQuoted);
40
+ }
41
+ listBuiltins(shellNames, shellBuiltins) {
42
+ return this.posix.listBuiltins(shellNames, shellBuiltins);
43
+ }
44
+ toLocalPath(value) {
45
+ if (!path.posix.isAbsolute(value))
46
+ return value;
47
+ return value.includes(Resources.windowsSeparator) ? null : `${this.share}${value.replaceAll(Resources.posixSeparator, Resources.windowsSeparator)}`;
48
+ }
49
+ readSearchFolders(value) {
50
+ return value.split(path.posix.delimiter).filter(t => path.posix.isAbsolute(t) && !t.includes(Resources.windowsSeparator)).map(t => `${this.share}${t.replaceAll(Resources.posixSeparator, Resources.windowsSeparator)}`);
51
+ }
52
+ toProgramCall(file, args) {
53
+ return new ProgramCall(this.launcher, [Resources.wslDistributionArgument, this.distribution, Resources.wslExecArgument, ...[file, ...args].map(t => this.toShellPath(t))]);
54
+ }
55
+ toShellPath(value) {
56
+ if (!value.toLowerCase().startsWith(`${this.share.toLowerCase()}${Resources.windowsSeparator}`))
57
+ return value;
58
+ return value.slice(this.share.length).replaceAll(Resources.windowsSeparator, Resources.posixSeparator);
59
+ }
60
+ }