@microsoft/inshellisense 0.0.1-rc.3 → 0.0.1-rc.31

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
@@ -1,29 +1,84 @@
1
1
  # inshellisense
2
2
 
3
- `inshellisense` provides IDE style autocomplete for shells. It's a terminal native runtime for [autocomplete](https://github.com/withfig/autocomplete) which has support for 600+ command line tools. `inshellisense` supports Windows, Linux, & MacOS.
3
+ `inshellisense` provides IDE style autocomplete for shells. It's a terminal native runtime for [autocomplete](https://github.com/withfig/autocomplete) which has support for 600+ command line tools. `inshellisense` supports Windows, Linux, & macOS.
4
4
 
5
- <p align="center"><img alt="demo of inshellisense working" src="/docs/demo.gif" height="450px"/></p>
5
+ <p align="center"><img alt="demo of inshellisense working" src="/docs/demo.gif"/></p>
6
6
 
7
7
  ## Getting Started
8
8
 
9
- ### Requirements
10
- - `node >= 16.x`
11
-
12
9
  ### Installation
13
10
 
11
+ **npm (recommended)**
14
12
  ```shell
15
13
  npm install -g @microsoft/inshellisense
14
+ is init
15
+ ```
16
+ **homebrew (macOS/linux)**
17
+ ```shell
18
+ brew tap microsoft/inshellisense https://github.com/microsoft/inshellisense
19
+ brew install inshellisense
20
+ is init
21
+ ```
22
+
23
+ ### Updating
24
+
25
+ ```shell
26
+ npm install -g @microsoft/inshellisense # OR brew upgrade inshellisense
27
+ is reinit
16
28
  ```
17
29
 
18
30
  ### Quickstart
19
31
 
20
- After completing the installation, you can already run `inshellisense --shell <shell>` to start the autocomplete session for your desired shell. Additionally, you can bind `inshellisense` to a keybinding of `CTRL+a` by running the below command. This brings the added advantages of automatically starting the autocomplete session with your current shell and injecting any accepted command into your shell's history.
32
+ 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.
33
+
34
+ ### Shell Plugin
35
+
36
+ If you'd like to automatically start inshellisense when you open your shell, run the respective command for your shell. After running the command, inshellisense will automatically open when you start any new shell session:
21
37
 
22
38
  ```shell
23
- inshellisense bind
39
+ # bash
40
+ is init bash >> ~/.bashrc
41
+
42
+ # zsh
43
+ is init zsh >> ~/.zshrc
44
+
45
+ # fish
46
+ is init fish >> ~/.config/fish/config.fish
47
+
48
+ # pwsh
49
+ is init pwsh | Add-Content $profile
50
+
51
+ # powershell
52
+ is init powershell | Add-Content $profile
53
+
54
+ # xonsh
55
+ is init xonsh >> ~/.xonshrc
56
+
57
+ # nushell
58
+ is init nu | save $nu.env-path --append
24
59
  ```
25
60
 
26
- Additionally, inshellisense is also aliased under `is` after install for convenience.
61
+ > [!NOTE]
62
+ > 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)
63
+
64
+ ### Usage
65
+
66
+ | Action | Command | Description |
67
+ | ------------------------------------- | ------- | ------------------------------------------------ |
68
+ | Start | `is` | Start inshellisense session on the current shell |
69
+ | Stop | `exit` | Stop inshellisense session on the current shell |
70
+ | Check If Inside Inshellisense Session | `is -c` | Check if shell inside inshellisense session |
71
+
72
+ #### Keybindings
73
+
74
+ All other keys are passed through to the shell. The keybindings below are only captured when the inshellisense suggestions are visible, otherwise they are passed through to the shell as well. These can be customized in the [config](#configuration).
75
+
76
+ | Action | Keybinding |
77
+ | ------------------------- | -------------- |
78
+ | Accept Current Suggestion | <kbd>tab</kbd> |
79
+ | View Next Suggestion | <kbd>↓</kbd> |
80
+ | View Previous Suggestion | <kbd>↑</kbd> |
81
+ | Dismiss Suggestions | <kbd>esc</kbd> |
27
82
 
28
83
  ## Integrations
29
84
 
@@ -34,6 +89,56 @@ inshellisense supports the following shells:
34
89
  - [fish](https://github.com/fish-shell/fish-shell)
35
90
  - [pwsh](https://github.com/PowerShell/PowerShell)
36
91
  - [powershell](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-windows-powershell) (Windows Powershell)
92
+ - [cmd](https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/cmd) _(experimental)_
93
+ - [xonsh](https://xon.sh/)
94
+ - [nushell](https://www.nushell.sh/)
95
+
96
+ ## Configuration
97
+
98
+ All configuration is done through a [toml](https://toml.io/) file. You can create this file at `~/.inshellisenserc` or, for XDG compliance, at `~/.config/inshellisense/rc.toml`. The [JSON schema](https://json-schema.org/) for the configuration file can be found [here](https://github.com/microsoft/inshellisense/blob/main/src/utils/config.ts).
99
+
100
+ ### Keybindings
101
+
102
+ You can customize the keybindings for inshellisense by adding a `bindings` section to your config file. The following is the default configuration for the [keybindings](#keybindings):
103
+
104
+ ```toml
105
+ [bindings.acceptSuggestion]
106
+ key = "tab"
107
+ # shift and ctrl are optional and default to false
108
+ shift = false
109
+ ctrl = false
110
+
111
+ [bindings.nextSuggestion]
112
+ key = "down"
113
+
114
+ [bindings.previousSuggestion]
115
+ key = "up"
116
+
117
+ [bindings.dismissSuggestions]
118
+ key = "escape"
119
+ ```
120
+
121
+ Key names are matched against the Node.js [keypress](https://nodejs.org/api/readline.html#readlineemitkeypresseventsstream-interface) events.
122
+
123
+ ### Alias Expansion
124
+
125
+ Inshellisense supports expanding aliases for bash/zsh shells. You can enable alias expansion in your config file:
126
+
127
+ ```toml
128
+ useAliases = true
129
+ ```
130
+
131
+ ### NerdFonts
132
+
133
+ If you are using a [NerdFont](https://www.nerdfonts.com/) patched font, you can enable the NerdFonts support in your config file:
134
+
135
+ ```toml
136
+ useNerdFont = true
137
+ ```
138
+
139
+ ## Unsupported Specs
140
+
141
+ Specs for the `az`, `gcloud`, & `aws` CLIs are not supported in inshellisense due to their large size.
37
142
 
38
143
  ## Contributing
39
144
 
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 -->
package/bin.js ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+ // Copyright (c) Microsoft Corporation.
3
+ // Licensed under the MIT License.
4
+
5
+ const { spawnSync } = require("child_process");
6
+ const path = require("path");
7
+
8
+ const platform = process.platform;
9
+ const arch = process.arch;
10
+
11
+ const platformArch = `${platform}-${arch}`;
12
+ const packageName = `@microsoft/inshellisense-${platformArch}`;
13
+ const binaryName = platform === "win32" ? `inshellisense-${platformArch}.exe` : `inshellisense-${platformArch}`;
14
+
15
+ try {
16
+ const platformPkgPath = require.resolve(`${packageName}/package.json`);
17
+ const platformPkgDir = path.dirname(platformPkgPath);
18
+ const binaryPath = path.join(platformPkgDir, binaryName);
19
+
20
+ const result = spawnSync(binaryPath, process.argv.slice(2), {
21
+ stdio: "inherit",
22
+ shell: false,
23
+ });
24
+
25
+ process.exit(result.status ?? 1);
26
+ } catch (err) {
27
+ console.error(`inshellisense: Platform ${platformArch} is not supported.`);
28
+ console.error(err.message);
29
+ process.exit(1);
30
+ }
package/package.json CHANGED
@@ -1,25 +1,8 @@
1
1
  {
2
2
  "name": "@microsoft/inshellisense",
3
- "version": "0.0.1-rc.3",
3
+ "version": "0.0.1-rc.31",
4
4
  "description": "IDE style command line auto complete",
5
- "type": "module",
6
- "bin": {
7
- "inshellisense": "./build/index.js",
8
- "is": "./build/index.js"
9
- },
10
- "files": [
11
- "build/**",
12
- "shell/**",
13
- "*.md",
14
- "LICENSE"
15
- ],
16
- "scripts": {
17
- "build": "tsc",
18
- "start": "node ./build/index.js",
19
- "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
20
- "lint": "eslint src/ --ext .ts,.tsx && prettier src/ --check",
21
- "lint:fix": "eslint src/ --ext .ts,.tsx --fix && prettier src/ --write"
22
- },
5
+ "license": "MIT",
23
6
  "repository": {
24
7
  "type": "git",
25
8
  "url": "git+https://github.com/microsoft/inshellisense.git"
@@ -27,33 +10,24 @@
27
10
  "author": {
28
11
  "name": "Microsoft Corporation"
29
12
  },
30
- "license": "MIT",
31
13
  "bugs": {
32
14
  "url": "https://github.com/microsoft/inshellisense/issues"
33
15
  },
34
- "homepage": "https://github.com/microsoft/inshellisense#readme",
35
- "dependencies": {
36
- "@withfig/autocomplete": "^2.633.0",
37
- "chalk": "^5.3.0",
38
- "commander": "^11.0.0",
39
- "ink": "^4.4.1",
40
- "react": "^18.2.0",
41
- "wrap-ansi": "^8.1.0"
16
+ "bin": {
17
+ "is": "bin.js",
18
+ "inshellisense": "bin.js"
42
19
  },
43
- "devDependencies": {
44
- "@tsconfig/node18": "^18.2.2",
45
- "@types/jest": "^29.5.5",
46
- "@types/react": "^18.2.24",
47
- "@typescript-eslint/eslint-plugin": "^6.7.4",
48
- "@typescript-eslint/parser": "^6.7.4",
49
- "@withfig/autocomplete-types": "^1.28.0",
50
- "eslint": "^8.51.0",
51
- "eslint-config-prettier": "^9.0.0",
52
- "eslint-plugin-header": "^3.1.1",
53
- "eslint-plugin-react": "^7.33.2",
54
- "jest": "^29.7.0",
55
- "prettier": "3.0.3",
56
- "ts-jest": "^29.1.1",
57
- "typescript": "^5.2.2"
20
+ "files": [
21
+ "*.md",
22
+ "LICENSE",
23
+ "bin.js"
24
+ ],
25
+ "optionalDependencies": {
26
+ "@microsoft/inshellisense-darwin-x64": "0.0.1-rc.31",
27
+ "@microsoft/inshellisense-darwin-arm64": "0.0.1-rc.31",
28
+ "@microsoft/inshellisense-linux-x64": "0.0.1-rc.31",
29
+ "@microsoft/inshellisense-linux-arm64": "0.0.1-rc.31",
30
+ "@microsoft/inshellisense-win32-x64": "0.0.1-rc.31",
31
+ "@microsoft/inshellisense-win32-arm64": "0.0.1-rc.31"
58
32
  }
59
- }
33
+ }
@@ -1,12 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { Command } from "commander";
4
- import { supportedShells } from "../utils/bindings.js";
5
- import { render } from "../ui/ui-bind.js";
6
- const action = async () => {
7
- await render();
8
- };
9
- const cmd = new Command("bind");
10
- cmd.description(`adds keybindings to the selected shell: ${supportedShells.join(", ")}`);
11
- cmd.action(action);
12
- export default cmd;
@@ -1,40 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { render } from "../ui/ui-root.js";
4
- import { executeShellCommandTTY } from "../runtime/utils.js";
5
- import { saveCommand, loadCommand } from "../utils/cache.js";
6
- import { supportedShells as shells } from "../utils/bindings.js";
7
- export const supportedShells = shells.join(", ");
8
- export const action = async (options) => {
9
- if (options.history) {
10
- process.stdout.write(await loadCommand());
11
- process.exit(0);
12
- }
13
- const shell = options.shell ?? "";
14
- if (!shells.map((s) => s.valueOf()).includes(shell)) {
15
- console.error(`Unsupported shell: '${shell}', supported shells: ${supportedShells}`);
16
- process.exit(1);
17
- }
18
- let executed = false;
19
- const commands = [];
20
- let result = { code: 0 };
21
- let startingCommand = options.command;
22
- while (options.duration === "session" || !executed) {
23
- const commandToExecute = await render(startingCommand);
24
- if (commandToExecute == null || commandToExecute.trim().toLowerCase() == "exit" || commandToExecute.trim().toLowerCase() == "logout") {
25
- result = { code: 0 };
26
- break;
27
- }
28
- commands.push(commandToExecute);
29
- result = await executeShellCommandTTY(shell, commandToExecute);
30
- executed = true;
31
- startingCommand = undefined;
32
- }
33
- await saveCommand(commands);
34
- if (result.code) {
35
- process.exit(result.code);
36
- }
37
- else {
38
- process.exit(0);
39
- }
40
- };
@@ -1,11 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { Command } from "commander";
4
- import { render } from "../ui/ui-uninstall.js";
5
- const action = async () => {
6
- await render();
7
- };
8
- const cmd = new Command("uninstall");
9
- cmd.description(`removes all bindings and configuration for inshellisense`);
10
- cmd.action(action);
11
- export default cmd;
package/build/index.js DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env node
2
- // Copyright (c) Microsoft Corporation.
3
- // Licensed under the MIT License.
4
- /* eslint-disable header/header */
5
- import { Command } from "commander";
6
- import bind from "./commands/bind.js";
7
- import uninstall from "./commands/uninstall.js";
8
- import { action, supportedShells } from "./commands/root.js";
9
- import { getVersion } from "./utils/version.js";
10
- const program = new Command();
11
- program
12
- .name("inshellisense")
13
- .description("IDE style command line auto complete")
14
- .version(await getVersion(), "-v, --version", "output the current version")
15
- .option("-s, --shell <shell>", `shell to use for command execution, supported shells: ${supportedShells}`)
16
- .option("-c, --command <commmand>", "command to use as initial input")
17
- .option("--history", "get the last command execute")
18
- .option("-d, --duration <duration>", "duration of the autocomplete session, supported durations: single, session", "session")
19
- .action(action);
20
- program.addCommand(bind);
21
- program.addCommand(uninstall);
22
- program.parse();
@@ -1,42 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- import { runTemplates } from "./template.js";
4
- import { buildExecuteShellCommand } from "./utils.js";
5
- const getGeneratorContext = () => {
6
- return {
7
- environmentVariables: Object.fromEntries(Object.entries(process.env).filter((entry) => entry[1] != null)),
8
- currentWorkingDirectory: process.cwd(),
9
- currentProcess: "",
10
- sshPrefix: "",
11
- isDangerous: false,
12
- searchTerm: "", // TODO: define search term
13
- };
14
- };
15
- // TODO: add support for caching, trigger, & getQueryTerm
16
- export const runGenerator = async (generator, tokens) => {
17
- const { script, postProcess, scriptTimeout, splitOn, custom, template } = generator;
18
- const executeShellCommand = buildExecuteShellCommand(scriptTimeout ?? 5000);
19
- const suggestions = [];
20
- try {
21
- if (script) {
22
- const scriptOutput = typeof script === "function" ? script(tokens) : script != null ? await executeShellCommand(script) : "";
23
- if (postProcess) {
24
- suggestions.push(...postProcess(scriptOutput, tokens));
25
- }
26
- else if (splitOn) {
27
- suggestions.push(...scriptOutput.split(splitOn).map((s) => ({ name: s })));
28
- }
29
- }
30
- if (custom) {
31
- suggestions.push(...(await custom(tokens, executeShellCommand, getGeneratorContext())));
32
- }
33
- if (template != null) {
34
- suggestions.push(...(await runTemplates(template)));
35
- }
36
- return suggestions;
37
- }
38
- catch (e) {
39
- /* empty */
40
- }
41
- return suggestions;
42
- };
@@ -1,3 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- export {};
@@ -1,63 +0,0 @@
1
- // Copyright (c) Microsoft Corporation.
2
- // Licensed under the MIT License.
3
- const cmdDelim = /(\|\|)|(&&)|(;)/;
4
- const spaceRegex = /\s/;
5
- export const parseCommand = (command) => {
6
- const lastCommand = command.split(cmdDelim).at(-1)?.trimStart();
7
- return lastCommand ? lex(lastCommand) : [];
8
- };
9
- const lex = (command) => {
10
- const tokens = [];
11
- let [readingQuotedString, readingFlag, readingCmd] = [false, false, false];
12
- let readingIdx = 0;
13
- let readingQuoteChar = "";
14
- [...command].forEach((char, idx) => {
15
- const reading = readingQuotedString || readingFlag || readingCmd;
16
- if (!reading && (char === `'` || char === `"`)) {
17
- [readingQuotedString, readingIdx, readingQuoteChar] = [true, idx, char];
18
- return;
19
- }
20
- else if (!reading && char === `-`) {
21
- [readingFlag, readingIdx] = [true, idx];
22
- return;
23
- }
24
- else if (!reading && !spaceRegex.test(char)) {
25
- [readingCmd, readingIdx] = [true, idx];
26
- return;
27
- }
28
- if (readingQuotedString && char === readingQuoteChar && command.at(idx - 1) !== "\\") {
29
- readingQuotedString = false;
30
- const complete = idx + 1 < command.length && spaceRegex.test(command[idx + 1]);
31
- tokens.push({
32
- token: command.slice(readingIdx, idx + 1),
33
- complete,
34
- isOption: false,
35
- });
36
- }
37
- else if ((readingFlag && spaceRegex.test(char)) || char === "=") {
38
- readingFlag = false;
39
- tokens.push({
40
- token: command.slice(readingIdx, idx),
41
- complete: true,
42
- isOption: true,
43
- });
44
- }
45
- else if (readingCmd && spaceRegex.test(char)) {
46
- readingCmd = false;
47
- tokens.push({
48
- token: command.slice(readingIdx, idx),
49
- complete: true,
50
- isOption: false,
51
- });
52
- }
53
- });
54
- const reading = readingQuotedString || readingFlag || readingCmd;
55
- if (reading) {
56
- tokens.push({
57
- token: command.slice(readingIdx),
58
- complete: false,
59
- isOption: false,
60
- });
61
- }
62
- return tokens;
63
- };