@microsoft/inshellisense 0.0.1-rc.15 → 0.0.1-rc.16

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
@@ -47,6 +47,8 @@ is init xonsh >> ~/.xonshrc
47
47
  is init nu >> $nu.env-path
48
48
  ```
49
49
 
50
+ When updating your shell configuration in the future, make sure the inshellisense plugin is the last command in the file.
51
+
50
52
  ### Usage
51
53
 
52
54
  | 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,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;
@@ -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(";");
@@ -17,10 +17,10 @@ var SuggestionIcons;
17
17
  SuggestionIcons["Default"] = "\uD83D\uDCC0";
18
18
  })(SuggestionIcons || (SuggestionIcons = {}));
19
19
  const getIcon = (icon, suggestionType) => {
20
- // TODO: enable fig icons once spacing is better
21
- // if (icon && /[^\u0000-\u00ff]/.test(icon)) {
22
- // return icon;
23
- // }
20
+ // eslint-disable-next-line no-control-regex
21
+ if (icon && /[^\u0000-\u00ff]/.test(icon)) {
22
+ return icon;
23
+ }
24
24
  switch (suggestionType) {
25
25
  case "arg":
26
26
  return SuggestionIcons.Argument;
@@ -6,14 +6,14 @@ import fsAsync from "node:fs/promises";
6
6
  import { getPathSeperator } from "../utils/shell.js";
7
7
  import log from "../utils/log.js";
8
8
  export const buildExecuteShellCommand = (timeout) => async ({ command, env, args, cwd }) => {
9
- const child = spawn(command, args, { cwd, env: { ...env, ISTERM: "1" } });
9
+ const child = spawn(command, args, { cwd, env: { ...process.env, ...env, ISTERM: "1" } });
10
10
  setTimeout(() => child.kill("SIGKILL"), timeout);
11
11
  let stdout = "";
12
12
  let stderr = "";
13
13
  child.stdout.on("data", (data) => (stdout += data));
14
14
  child.stderr.on("data", (data) => (stderr += data));
15
15
  child.on("error", (err) => {
16
- log.debug({ msg: "shell command failed", e: err.message });
16
+ log.debug({ msg: "shell command failed", command, args, e: err.message });
17
17
  });
18
18
  return new Promise((resolve) => {
19
19
  child.on("close", (code) => {
@@ -8,6 +8,7 @@ import fs from "node:fs";
8
8
  import url from "node:url";
9
9
  import os from "node:os";
10
10
  import fsAsync from "node:fs/promises";
11
+ import log from "./log.js";
11
12
  export var Shell;
12
13
  (function (Shell) {
13
14
  Shell["Bash"] = "bash";
@@ -49,6 +50,14 @@ export const setupZshDotfiles = async () => {
49
50
  await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-env.zsh"), path.join(zdotdir, ".zshenv"));
50
51
  await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-login.zsh"), path.join(zdotdir, ".zlogin"));
51
52
  };
53
+ const findPareentProcess = async () => {
54
+ try {
55
+ return (await find("pid", process.ppid)).at(0);
56
+ }
57
+ catch (e) {
58
+ log.debug({ msg: `error finding parent process: ${e}` });
59
+ }
60
+ };
52
61
  export const inferShell = async () => {
53
62
  // try getting shell from shell specific env variables
54
63
  if (process.env.NU_VERSION != null) {
@@ -77,7 +86,7 @@ export const inferShell = async () => {
77
86
  /* empty */
78
87
  }
79
88
  // try getting shell from parent process
80
- const processResult = (await find("pid", process.ppid)).at(0);
89
+ const processResult = await findPareentProcess();
81
90
  const name = processResult?.name;
82
91
  return name != null ? supportedShells.find((shell) => name.includes(shell)) : undefined;
83
92
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/inshellisense",
3
- "version": "0.0.1-rc.15",
3
+ "version": "0.0.1-rc.16",
4
4
  "description": "IDE style command line auto complete",
5
5
  "type": "module",
6
6
  "engines": {
@@ -41,6 +41,7 @@
41
41
  "dependencies": {
42
42
  "@homebridge/node-pty-prebuilt-multiarch": "^0.11.12",
43
43
  "@withfig/autocomplete": "2.651.0",
44
+ "@xterm/addon-unicode11": "^0.8.0",
44
45
  "@xterm/headless": "^5.5.0",
45
46
  "ajv": "^8.12.0",
46
47
  "ansi-escapes": "^6.2.0",
@@ -1,9 +1,12 @@
1
1
  if [[ -f $USER_ZDOTDIR/.zshenv ]]; then
2
+ IS_ZDOTDIR=$ZDOTDIR
2
3
  ZDOTDIR=$USER_ZDOTDIR
3
4
 
4
5
  # prevent recursion
5
- if [[ $USER_ZDOTDIR != $ZDOTDIR ]]; then
6
- ZDOTDIR=$USER_ZDOTDIR
6
+ if [[ $USER_ZDOTDIR != $IS_ZDOTDIR ]]; then
7
7
  . $USER_ZDOTDIR/.zshenv
8
8
  fi
9
+
10
+ USER_ZDOTDIR=$ZDOTDIR
11
+ ZDOTDIR=$IS_ZDOTDIR
9
12
  fi
@@ -1,3 +1,5 @@
1
+ autoload -U add-zsh-hook
2
+
1
3
  if [[ -f $USER_ZDOTDIR/.zshrc ]]; then
2
4
  ZDOTDIR=$USER_ZDOTDIR
3
5
  . $USER_ZDOTDIR/.zshrc
@@ -25,6 +27,12 @@ __is_escape_value() {
25
27
  token="\\\\"
26
28
  elif [ "$byte" = ";" ]; then
27
29
  token="\\x3b"
30
+ elif [ "$byte" = $'\n' ]; then
31
+ token="\x0a"
32
+ elif [ "$byte" = $'\e' ]; then
33
+ token="\\x1b"
34
+ elif [ "$byte" = $'\a' ]; then
35
+ token="\\x07"
28
36
  else
29
37
  token="$byte"
30
38
  fi
@@ -44,6 +44,8 @@ __is_escape_value() {
44
44
  token="\x0a"
45
45
  elif [ "$byte" = $'\e' ]; then
46
46
  token="\\x1b"
47
+ elif [ "$byte" = $'\a' ]; then
48
+ token="\\x07"
47
49
  else
48
50
  token="$byte"
49
51
  fi
@@ -9,6 +9,7 @@ function __is_escape_value
9
9
  | string replace -a '\\' '\\\\' \
10
10
  | string replace -a ';' '\\x3b' \
11
11
  | string replace -a \e '\\x1b' \
12
+ | string replace -a \a '\\x07' \
12
13
  | string split \n | string join '\x0a' \
13
14
  ;
14
15
  end
@@ -1,4 +1,4 @@
1
- let __is_escape_value = {|x| $x | str replace --all "\\" "\\\\" | str replace --all ";" "\\x3b" | str replace --all "\n" '\x0a' | str replace --all "\e" "\\x1b" }
1
+ let __is_escape_value = {|x| $x | str replace --all "\\" "\\\\" | str replace --all ";" "\\x3b" | str replace --all "\n" '\x0a' | str replace --all "\e" "\\x1b" | str replace --all "\a" "\\x07" }
2
2
  let __is_original_PROMPT_COMMAND = if 'PROMPT_COMMAND' in $env { $env.PROMPT_COMMAND } else { "" }
3
3
  let __is_original_PROMPT_INDICATOR = if 'PROMPT_INDICATOR' in $env { $env.PROMPT_INDICATOR } else { "" }
4
4
 
@@ -8,7 +8,7 @@ if ($env:ISTERM_TESTING -eq "1") {
8
8
  }
9
9
 
10
10
  function Global:__IS-Escape-Value([string]$value) {
11
- [regex]::Replace($value, "[$([char]0x1b)\\\n;]", { param($match)
11
+ [regex]::Replace($value, "[$([char]0x1b)$([char]0x07)\\\n;]", { param($match)
12
12
  -Join (
13
13
  [System.Text.Encoding]::UTF8.GetBytes($match.Value) | ForEach-Object { '\x{0:x2}' -f $_ }
14
14
  )
@@ -12,7 +12,7 @@ def __is_escape_value(value: str) -> str:
12
12
  byte_list = [bytes([byte]).decode("utf-8") for byte in list(value.encode("utf-8"))]
13
13
  return "".join(
14
14
  [
15
- "\\x3b" if byte == ";" else "\\\\" if byte == "\\" else "\\x1b" if byte == "\x1b" else "\x0a" if byte == "\n" else byte
15
+ "\\x3b" if byte == ";" else "\\\\" if byte == "\\" else "\\x1b" if byte == "\x1b" else "\x0a" if byte == "\n"else "\\x07" if byte == "\x07" else byte
16
16
  for byte in byte_list
17
17
  ]
18
18
  )
package/todo.md ADDED
@@ -0,0 +1,4 @@
1
+ - [x] improve wrapping handling
2
+ `const wrapped = line?.isWrapped || (this.#terminal.buffer.active.cursorY + this.#terminal.buffer.active.baseY) != lineY`
3
+ `lineY < this.#terminal.rows`
4
+ - [ ] handle paths with spaces in them on bash (ignore pwsh for now as it fails cd anyway)