@microsoft/inshellisense 0.0.1-rc.15 → 0.0.1-rc.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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) Microsoft Corporation.
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE
1
+ MIT License
2
+
3
+ Copyright (c) Microsoft Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
package/README.md CHANGED
@@ -18,7 +18,7 @@ npm install -g @microsoft/inshellisense
18
18
 
19
19
  ### Quickstart
20
20
 
21
- After completing the installation, you can run `is` to start the autocomplete session for your desired shell. Additionally, inshellisense is also aliased under `inshellisense` after installation.
21
+ After completing the installation, run `is doctor` to verify your installation was successful. You can run `is` to start the autocomplete session for your desired shell. Additionally, inshellisense is also aliased under `inshellisense` after installation.
22
22
 
23
23
  ### Shell Plugin
24
24
 
@@ -35,18 +35,21 @@ is init zsh >> ~/.zshrc
35
35
  is init fish >> ~/.config/fish/config.fish
36
36
 
37
37
  # pwsh
38
- is init pwsh >> $profile
38
+ is init pwsh | Add-Content $profile
39
39
 
40
40
  # powershell
41
- is init powershell >> $profile
41
+ is init powershell | Add-Content $profile
42
42
 
43
43
  # xonsh
44
44
  is init xonsh >> ~/.xonshrc
45
45
 
46
46
  # nushell
47
- is init nu >> $nu.env-path
47
+ is init nu | save $nu.env-path --append
48
48
  ```
49
49
 
50
+ > [!NOTE]
51
+ > When updating your shell configuration in the future, make sure the inshellisense plugin is the last command in the file. Including commands after it may break the configuration (ex. initializing your shell plugin manager after the inshellisense plugin)
52
+
50
53
  ### Usage
51
54
 
52
55
  | Action | Command | Description |
package/SECURITY.md CHANGED
@@ -1,41 +1,41 @@
1
- <!-- BEGIN MICROSOFT SECURITY.MD V0.0.9 BLOCK -->
2
-
3
- ## Security
4
-
5
- Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin).
6
-
7
- If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.
8
-
9
- ## Reporting Security Issues
10
-
11
- **Please do not report security vulnerabilities through public GitHub issues.**
12
-
13
- Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).
14
-
15
- If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp).
16
-
17
- You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18
-
19
- Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20
-
21
- * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22
- * Full paths of source file(s) related to the manifestation of the issue
23
- * The location of the affected source code (tag/branch/commit or direct URL)
24
- * Any special configuration required to reproduce the issue
25
- * Step-by-step instructions to reproduce the issue
26
- * Proof-of-concept or exploit code (if possible)
27
- * Impact of the issue, including how an attacker might exploit the issue
28
-
29
- This information will help us triage your report more quickly.
30
-
31
- If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.
32
-
33
- ## Preferred Languages
34
-
35
- We prefer all communications to be in English.
36
-
37
- ## Policy
38
-
39
- Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
40
-
41
- <!-- END MICROSOFT SECURITY.MD BLOCK -->
1
+ <!-- BEGIN MICROSOFT SECURITY.MD V0.0.9 BLOCK -->
2
+
3
+ ## Security
4
+
5
+ Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet) and [Xamarin](https://github.com/xamarin).
6
+
7
+ If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://aka.ms/security.md/definition), please report it to us as described below.
8
+
9
+ ## Reporting Security Issues
10
+
11
+ **Please do not report security vulnerabilities through public GitHub issues.**
12
+
13
+ Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://aka.ms/security.md/msrc/create-report).
14
+
15
+ If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://aka.ms/security.md/msrc/pgp).
16
+
17
+ You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc).
18
+
19
+ Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue:
20
+
21
+ * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
22
+ * Full paths of source file(s) related to the manifestation of the issue
23
+ * The location of the affected source code (tag/branch/commit or direct URL)
24
+ * Any special configuration required to reproduce the issue
25
+ * Step-by-step instructions to reproduce the issue
26
+ * Proof-of-concept or exploit code (if possible)
27
+ * Impact of the issue, including how an attacker might exploit the issue
28
+
29
+ This information will help us triage your report more quickly.
30
+
31
+ If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://aka.ms/security.md/msrc/bounty) page for more details about our active programs.
32
+
33
+ ## Preferred Languages
34
+
35
+ We prefer all communications to be in English.
36
+
37
+ ## Policy
38
+
39
+ Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://aka.ms/security.md/cvd).
40
+
41
+ <!-- END MICROSOFT SECURITY.MD BLOCK -->
@@ -0,0 +1,10 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import os from "node:os";
4
+ import { getSuggestions } from "../runtime/runtime.js";
5
+ import { Shell } from "../utils/shell.js";
6
+ export const action = async (input) => {
7
+ const suggestions = await getSuggestions(input, process.cwd(), os.platform() === "win32" ? Shell.Cmd : Shell.Bash);
8
+ process.stdout.write(JSON.stringify(suggestions));
9
+ process.exit(0);
10
+ };
@@ -0,0 +1,11 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { Command } from "commander";
4
+ import { render } from "../ui/ui-doctor.js";
5
+ const action = async () => {
6
+ await render();
7
+ };
8
+ const cmd = new Command("doctor");
9
+ cmd.description(`checks the health of this inshellisense installation`);
10
+ cmd.action(action);
11
+ export default cmd;
@@ -1,18 +1,24 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
3
  import { Command } from "commander";
4
- import { initSupportedShells as shells, getShellConfig } from "../utils/shell.js";
4
+ import { createShellConfigs, initSupportedShells as shells, getShellSourceCommand } from "../utils/shell.js";
5
5
  const supportedShells = shells.join(", ");
6
- const action = (program) => async (shell) => {
6
+ const action = (program) => async (shell, options) => {
7
+ if (options.generateFullConfigs) {
8
+ await createShellConfigs();
9
+ return;
10
+ }
11
+ if (shell == null)
12
+ program.error(`Shell is required, supported shells: ${supportedShells}`, { exitCode: 1 });
7
13
  if (!shells.map((s) => s.valueOf()).includes(shell)) {
8
14
  program.error(`Unsupported shell: '${shell}', supported shells: ${supportedShells}`, { exitCode: 1 });
9
15
  }
10
- const config = getShellConfig(shell);
11
- process.stdout.write(`\n\n# ---------------- inshellisense shell plugin ----------------\n${config}`);
12
- process.exit(0);
16
+ const config = getShellSourceCommand(shell);
17
+ process.stdout.write(`\n\n${config}`);
13
18
  };
14
19
  const cmd = new Command("init");
15
- cmd.description(`generates shell configurations for the provided shell`);
16
- cmd.argument("<shell>", `shell to generate configuration for, supported shells: ${supportedShells}`);
20
+ cmd.description(`generates shell configurations and prints the source command for the specified shell`);
21
+ cmd.argument("[shell]", `shell to generate for, supported shells: ${supportedShells}`);
22
+ cmd.option("--generate-full-configs");
17
23
  cmd.action(action(cmd));
18
24
  export default cmd;
@@ -0,0 +1,38 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { render, renderConfirmation } from "../ui/ui-root.js";
4
+ import { Shell, supportedShells as shells, setupZshDotfiles, setupBashPreExec } from "../utils/shell.js";
5
+ import { inferShell } from "../utils/shell.js";
6
+ import { loadConfig } from "../utils/config.js";
7
+ import log from "../utils/log.js";
8
+ import { loadAliases } from "../runtime/alias.js";
9
+ import { loadLocalSpecsSet } from "../runtime/runtime.js";
10
+ import { program } from "./root.js";
11
+ export const supportedShells = shells.join(", ");
12
+ export const action = async (options) => {
13
+ const inISTerm = process.env.ISTERM === "1";
14
+ if (options.check || inISTerm) {
15
+ process.stdout.write(renderConfirmation(inISTerm));
16
+ process.exit(0);
17
+ }
18
+ if (options.verbose)
19
+ await log.enable();
20
+ await loadConfig(program);
21
+ await loadLocalSpecsSet();
22
+ const shell = options.shell ?? (await inferShell());
23
+ if (shell == null) {
24
+ program.error(`Unable to identify shell, use the -s/--shell option to provide your shell`, { exitCode: 1 });
25
+ return;
26
+ }
27
+ if (!shells.map((s) => s.valueOf()).includes(shell)) {
28
+ program.error(`Unsupported shell: '${shell}', supported shells: ${supportedShells}`, { exitCode: 1 });
29
+ }
30
+ if (shell == Shell.Zsh) {
31
+ await setupZshDotfiles();
32
+ }
33
+ else if (shell == Shell.Bash) {
34
+ await setupBashPreExec();
35
+ }
36
+ await loadAliases(shell);
37
+ await render(shell, options.test ?? false, options.login ?? false);
38
+ };
@@ -18,6 +18,7 @@ export const action = (program) => async (options) => {
18
18
  await log.enable();
19
19
  await loadConfig(program);
20
20
  await loadLocalSpecsSet();
21
+ log.overrideConsole();
21
22
  const shell = options.shell ?? (await inferShell());
22
23
  if (shell == null) {
23
24
  program.error(`Unable to identify shell, use the -s/--shell option to provide your shell`, { exitCode: 1 });
@@ -0,0 +1,18 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import { Command } from "commander";
4
+ import { shellEnvSupportedShells as shells, getShellConfig } from "../utils/shell.js";
5
+ const supportedShells = shells.join(", ");
6
+ const action = (program) => async (shell) => {
7
+ if (!shells.map((s) => s.valueOf()).includes(shell)) {
8
+ program.error(`Unsupported shell: '${shell}', supported shells: ${supportedShells}`, { exitCode: 1 });
9
+ }
10
+ const config = getShellConfig(shell);
11
+ process.stdout.write(`\n\n# ---------------- inshellisense shell plugin ----------------\n${config}`);
12
+ process.exit(0);
13
+ };
14
+ const cmd = new Command("shellenv");
15
+ cmd.description(`generates shell configurations for the provided shell`);
16
+ cmd.argument("<shell>", `shell to generate configuration for, supported shells: ${supportedShells}`);
17
+ cmd.action(action(cmd));
18
+ export default cmd;
package/build/index.js CHANGED
@@ -7,6 +7,7 @@ import complete from "./commands/complete.js";
7
7
  import uninstall from "./commands/uninstall.js";
8
8
  import init from "./commands/init.js";
9
9
  import specs from "./commands/specs/root.js";
10
+ import doctor from "./commands/doctor.js";
10
11
  import { action, supportedShells } from "./commands/root.js";
11
12
  import { getVersion } from "./utils/version.js";
12
13
  const program = new Command();
@@ -31,4 +32,5 @@ program.addCommand(complete);
31
32
  program.addCommand(uninstall);
32
33
  program.addCommand(init);
33
34
  program.addCommand(specs);
35
+ program.addCommand(doctor);
34
36
  program.parse();
@@ -154,12 +154,9 @@ export class CommandManager {
154
154
  const dim = (cell?.isDim() ?? 0) > 0;
155
155
  const italic = (cell?.isItalic() ?? 0) > 0;
156
156
  const dullColor = color == 8 || color == 7 || (color ?? 0) > 235 || (color == 15 && dim);
157
- const dullItalic = (color ?? 0) > 235 || (dullColor && italic);
158
- if (this.#shell == Shell.Powershell) {
159
- return false;
160
- }
161
- else if (this.#shell == Shell.Pwsh) {
162
- return dullItalic;
157
+ const dimItalic = dim || italic;
158
+ if (this.#shell == Shell.Pwsh || this.#shell == Shell.Powershell) {
159
+ return dimItalic;
163
160
  }
164
161
  return dullColor;
165
162
  }
@@ -7,6 +7,7 @@ import path from "node:path";
7
7
  import url from "node:url";
8
8
  import fs from "node:fs";
9
9
  import stripAnsi from "strip-ansi";
10
+ import { Unicode11Addon } from "@xterm/addon-unicode11";
10
11
  import pty from "@homebridge/node-pty-prebuilt-multiarch";
11
12
  import { Shell, userZdotdir, zdotdir } from "../utils/shell.js";
12
13
  import { IsTermOscPs, IstermOscPt, IstermPromptStart, IstermPromptEnd } from "../utils/ansi.js";
@@ -44,7 +45,10 @@ export class ISTerm {
44
45
  this.cols = this.#pty.cols;
45
46
  this.rows = this.#pty.rows;
46
47
  this.process = this.#pty.process;
48
+ const unicode11Addon = new Unicode11Addon();
47
49
  this.#term = new xterm.Terminal({ allowProposedApi: true, rows, cols });
50
+ this.#term.loadAddon(unicode11Addon);
51
+ this.#term.unicode.activeVersion = "11";
48
52
  this.#term.parser.registerOscHandler(IsTermOscPs, (data) => this._handleIsSequence(data));
49
53
  this.#commandManager = new CommandManager(this.#term, shell);
50
54
  this.#shell = shell;
@@ -86,7 +90,9 @@ export class ISTerm {
86
90
  return cwd;
87
91
  }
88
92
  _sanitizedPrompt(prompt) {
89
- return stripAnsi(prompt);
93
+ // eslint-disable-next-line no-control-regex -- strip OSC control sequences
94
+ const oscStrippedPrompt = prompt.replace(/\x1b\][0-9]+;.*\x07/g, "");
95
+ return stripAnsi(oscStrippedPrompt);
90
96
  }
91
97
  _handleIsSequence(data) {
92
98
  const argsIndex = data.indexOf(";");
@@ -7,7 +7,7 @@ import { buildExecuteShellCommand } from "./utils.js";
7
7
  import os from "node:os";
8
8
  const loadedAliases = {};
9
9
  const platform = os.platform();
10
- const executeShellCommand = buildExecuteShellCommand(5000);
10
+ const executeShellCommand = await buildExecuteShellCommand(5000);
11
11
  const loadBashAliases = async () => {
12
12
  const shellTarget = platform == "win32" ? await gitBashPath() : Shell.Bash;
13
13
  const { stdout, stderr, status } = await executeShellCommand({ command: shellTarget, args: ["-i", "-c", "alias"], cwd: process.cwd() });
@@ -20,7 +20,7 @@ const loadBashAliases = async () => {
20
20
  .split("\n")
21
21
  .forEach((line) => {
22
22
  const [alias, ...commandSegments] = line.replace("alias ", "").replaceAll("'\\''", "'").split("=");
23
- loadedAliases[alias] = parseCommand(commandSegments.join("=").slice(1, -1) + " ");
23
+ loadedAliases[alias] = parseCommand(commandSegments.join("=").slice(1, -1) + " ", Shell.Bash);
24
24
  });
25
25
  };
26
26
  const loadZshAliases = async () => {
@@ -34,7 +34,7 @@ const loadZshAliases = async () => {
34
34
  .split("\n")
35
35
  .forEach((line) => {
36
36
  const [alias, ...commandSegments] = line.replaceAll("'\\''", "'").split("=");
37
- loadedAliases[alias] = parseCommand(commandSegments.join("=").slice(1, -1) + " ");
37
+ loadedAliases[alias] = parseCommand(commandSegments.join("=").slice(1, -1) + " ", Shell.Zsh);
38
38
  });
39
39
  };
40
40
  export const loadAliases = async (shell) => {
@@ -17,7 +17,7 @@ const getGeneratorContext = (cwd) => {
17
17
  export const runGenerator = async (generator, tokens, cwd) => {
18
18
  // TODO: support trigger
19
19
  const { script, postProcess, scriptTimeout, splitOn, custom, template, filterTemplateSuggestions } = generator;
20
- const executeShellCommand = buildExecuteShellCommand(scriptTimeout ?? 5000);
20
+ const executeShellCommand = await buildExecuteShellCommand(scriptTimeout ?? 5000);
21
21
  const suggestions = [];
22
22
  try {
23
23
  if (script) {
@@ -1,19 +1,48 @@
1
1
  // Copyright (c) Microsoft Corporation.
2
2
  // Licensed under the MIT License.
3
+ import wcwidth from "wcwidth";
4
+ import { getShellWhitespaceEscapeChar } from "./utils.js";
3
5
  const cmdDelim = /(\|\|)|(&&)|(;)|(\|)/;
4
6
  const spaceRegex = /\s/;
5
- export const parseCommand = (command) => {
7
+ export const parseCommand = (command, shell) => {
6
8
  const lastCommand = command.split(cmdDelim).at(-1)?.trimStart();
7
- return lastCommand ? lex(lastCommand) : [];
9
+ const tokens = lastCommand ? lex(lastCommand, shell) : [];
10
+ return sanitizeTokens(tokens, shell);
8
11
  };
9
- const lex = (command) => {
12
+ const sanitizeTokens = (cmdTokens, shell) => unwrapQuotedTokens(unescapeSpaceTokens(cmdTokens, shell), shell);
13
+ // remove escapes around spaces
14
+ const unescapeSpaceTokens = (cmdTokens, shell) => {
15
+ const escapeChar = getShellWhitespaceEscapeChar(shell);
16
+ return cmdTokens.map((cmdToken) => {
17
+ const { token, isQuoted } = cmdToken;
18
+ if (!isQuoted && token.includes(`${escapeChar} `)) {
19
+ return { ...cmdToken, token: token.replaceAll(`${escapeChar} `, " ") };
20
+ }
21
+ return cmdToken;
22
+ });
23
+ };
24
+ // need to unwrap tokens that are quoted with content after the quotes like `"hello"world`
25
+ const unwrapQuotedTokens = (cmdTokens, shell) => {
26
+ const escapeChar = getShellWhitespaceEscapeChar(shell);
27
+ return cmdTokens.map((cmdToken) => {
28
+ const { token, isQuoteContinued } = cmdToken;
29
+ if (isQuoteContinued) {
30
+ const quoteChar = token[0];
31
+ const unquotedToken = token.replaceAll(`${escapeChar}${quoteChar}`, "\u001B").replaceAll(quoteChar, "").replaceAll("\u001B", quoteChar);
32
+ return { ...cmdToken, token: unquotedToken };
33
+ }
34
+ return cmdToken;
35
+ });
36
+ };
37
+ const lex = (command, shell) => {
10
38
  const tokens = [];
11
- let [readingQuotedString, readingFlag, readingCmd] = [false, false, false];
39
+ const escapeChar = getShellWhitespaceEscapeChar(shell);
40
+ let [readingQuotedString, readingQuoteContinuedString, readingFlag, readingCmd] = [false, false, false, false];
12
41
  let readingIdx = 0;
13
42
  let readingQuoteChar = "";
14
43
  [...command].forEach((char, idx) => {
15
- const reading = readingQuotedString || readingFlag || readingCmd;
16
- if (!reading && (char === `'` || char === `"`)) {
44
+ const reading = readingQuotedString || readingQuoteContinuedString || readingFlag || readingCmd;
45
+ if (!reading && (char === `'` || char === `"` || char == "`")) {
17
46
  [readingQuotedString, readingIdx, readingQuoteChar] = [true, idx, char];
18
47
  return;
19
48
  }
@@ -25,46 +54,76 @@ const lex = (command) => {
25
54
  [readingCmd, readingIdx] = [true, idx];
26
55
  return;
27
56
  }
28
- if (readingQuotedString && char === readingQuoteChar && command.at(idx - 1) !== "\\") {
57
+ if (readingQuotedString && char === readingQuoteChar && command.at(idx - 1) !== escapeChar && !spaceRegex.test(command.at(idx + 1) ?? " ")) {
58
+ readingQuotedString = false;
59
+ readingQuoteContinuedString = true;
60
+ }
61
+ else if (readingQuotedString && char === readingQuoteChar && command.at(idx - 1) !== escapeChar) {
29
62
  readingQuotedString = false;
30
63
  const complete = idx + 1 < command.length && spaceRegex.test(command[idx + 1]);
31
64
  tokens.push({
32
65
  token: command.slice(readingIdx + 1, idx),
66
+ tokenLength: wcwidth(command.slice(readingIdx + 1, idx)) + 2,
33
67
  complete,
34
68
  isOption: false,
35
69
  isQuoted: true,
36
70
  });
37
71
  }
72
+ else if (readingQuoteContinuedString && spaceRegex.test(char) && command.at(idx - 1) !== escapeChar) {
73
+ readingQuoteContinuedString = false;
74
+ tokens.push({
75
+ token: command.slice(readingIdx, idx),
76
+ tokenLength: wcwidth(command.slice(readingIdx, idx)),
77
+ complete: true,
78
+ isOption: false,
79
+ isQuoted: true,
80
+ isQuoteContinued: true,
81
+ });
82
+ }
38
83
  else if ((readingFlag && spaceRegex.test(char)) || char === "=") {
39
84
  readingFlag = false;
40
85
  tokens.push({
41
86
  token: command.slice(readingIdx, idx),
87
+ tokenLength: wcwidth(command.slice(readingIdx, idx)),
42
88
  complete: true,
43
89
  isOption: true,
44
90
  });
45
91
  }
46
- else if (readingCmd && spaceRegex.test(char) && command.at(idx - 1) !== "\\") {
92
+ else if (readingCmd && spaceRegex.test(char) && command.at(idx - 1) !== escapeChar) {
47
93
  readingCmd = false;
48
94
  tokens.push({
49
95
  token: command.slice(readingIdx, idx),
96
+ tokenLength: wcwidth(command.slice(readingIdx, idx)),
50
97
  complete: true,
51
98
  isOption: false,
52
99
  });
53
100
  }
54
101
  });
55
- const reading = readingQuotedString || readingFlag || readingCmd;
102
+ const reading = readingQuotedString || readingQuoteContinuedString || readingFlag || readingCmd;
56
103
  if (reading) {
57
104
  if (readingQuotedString) {
58
105
  tokens.push({
59
106
  token: command.slice(readingIdx + 1),
107
+ tokenLength: wcwidth(command.slice(readingIdx + 1)) + 1,
108
+ complete: false,
109
+ isOption: false,
110
+ isQuoted: true,
111
+ });
112
+ }
113
+ else if (readingQuoteContinuedString) {
114
+ tokens.push({
115
+ token: command.slice(readingIdx),
116
+ tokenLength: wcwidth(command.slice(readingIdx)),
60
117
  complete: false,
61
118
  isOption: false,
62
119
  isQuoted: true,
120
+ isQuoteContinued: true,
63
121
  });
64
122
  }
65
123
  else {
66
124
  tokens.push({
67
125
  token: command.slice(readingIdx),
126
+ tokenLength: wcwidth(command.slice(readingIdx)),
68
127
  complete: false,
69
128
  isOption: readingFlag,
70
129
  });