@microsoft/inshellisense 0.0.1-rc.1 → 0.0.1-rc.2

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.
@@ -1,9 +1,9 @@
1
- # Microsoft Open Source Code of Conduct
2
-
3
- This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4
-
5
- Resources:
6
-
7
- - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8
- - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9
- - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
1
+ # Microsoft Open Source Code of Conduct
2
+
3
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
4
+
5
+ Resources:
6
+
7
+ - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
8
+ - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
9
+ - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
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,55 +1,58 @@
1
- # inshellisense
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.
4
-
5
- <p align="center"><img alt="demo of inshellisense working" src="/docs/demo.gif" height="450px"/></p>
6
-
7
- ## Getting Started
8
-
9
- ### Installation
10
-
11
- ```shell
12
- npm install -g @microsoft/inshellisense
13
- ```
14
-
15
- ### Quickstart
16
-
17
- 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.
18
-
19
- ```shell
20
- inshellisense bind
21
- ```
22
-
23
- Additionally, inshellisense is also aliased under `is` after install for convenience.
24
-
25
- ## Integrations
26
-
27
- inshellisense supports the following shells:
28
-
29
- - [bash](https://www.gnu.org/software/bash/)
30
- - [zsh](https://www.zsh.org/)
31
- - [fish](https://github.com/fish-shell/fish-shell)
32
- - [pwsh](https://github.com/PowerShell/PowerShell)
33
- - [powershell](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-windows-powershell) (Windows Powershell)
34
-
35
- ## Contributing
36
-
37
- This project welcomes contributions and suggestions. Most contributions require you to agree to a
38
- Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
39
- the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
40
-
41
- When you submit a pull request, a CLA bot will automatically determine whether you need to provide
42
- a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
43
- provided by the bot. You will only need to do this once across all repos using our CLA.
44
-
45
- This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
46
- For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
47
- contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
48
-
49
- ## Trademarks
50
-
51
- This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
52
- trademarks or logos is subject to and must follow
53
- [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
54
- Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
55
- Any use of third-party trademarks or logos are subject to those third-party's policies.
1
+ # inshellisense
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.
4
+
5
+ <p align="center"><img alt="demo of inshellisense working" src="/docs/demo.gif" height="450px"/></p>
6
+
7
+ ## Getting Started
8
+
9
+ ### Requirements
10
+ - `node >= 16.x`
11
+
12
+ ### Installation
13
+
14
+ ```shell
15
+ npm install -g @microsoft/inshellisense
16
+ ```
17
+
18
+ ### Quickstart
19
+
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.
21
+
22
+ ```shell
23
+ inshellisense bind
24
+ ```
25
+
26
+ Additionally, inshellisense is also aliased under `is` after install for convenience.
27
+
28
+ ## Integrations
29
+
30
+ inshellisense supports the following shells:
31
+
32
+ - [bash](https://www.gnu.org/software/bash/)
33
+ - [zsh](https://www.zsh.org/)
34
+ - [fish](https://github.com/fish-shell/fish-shell)
35
+ - [pwsh](https://github.com/PowerShell/PowerShell)
36
+ - [powershell](https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/starting-windows-powershell) (Windows Powershell)
37
+
38
+ ## Contributing
39
+
40
+ This project welcomes contributions and suggestions. Most contributions require you to agree to a
41
+ Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
42
+ the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
43
+
44
+ When you submit a pull request, a CLA bot will automatically determine whether you need to provide
45
+ a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
46
+ provided by the bot. You will only need to do this once across all repos using our CLA.
47
+
48
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
49
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
50
+ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
51
+
52
+ ## Trademarks
53
+
54
+ This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft
55
+ trademarks or logos is subject to and must follow
56
+ [Microsoft's Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
57
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
58
+ Any use of third-party trademarks or logos are subject to those third-party's policies.
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/SUPPORT.md CHANGED
@@ -1,13 +1,13 @@
1
- # Support
2
-
3
- ## How to file issues and get help
4
-
5
- This project uses GitHub Issues to track bugs and feature requests. Please search the existing
6
- issues before filing new issues to avoid duplicates. For new issues, file your bug or
7
- feature request as a new Issue.
8
-
9
- For help and questions about using this project, create a new Github Discussion.
10
-
11
- ## Microsoft Support Policy
12
-
13
- Support for this project is limited to the resources listed above.
1
+ # Support
2
+
3
+ ## How to file issues and get help
4
+
5
+ This project uses GitHub Issues to track bugs and feature requests. Please search the existing
6
+ issues before filing new issues to avoid duplicates. For new issues, file your bug or
7
+ feature request as a new Issue.
8
+
9
+ For help and questions about using this project, create a new Github Discussion.
10
+
11
+ ## Microsoft Support Policy
12
+
13
+ Support for this project is limited to the resources listed above.
@@ -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-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 CHANGED
@@ -4,6 +4,7 @@
4
4
  /* eslint-disable header/header */
5
5
  import { Command } from "commander";
6
6
  import bind from "./commands/bind.js";
7
+ import uninstall from "./commands/uninstall.js";
7
8
  import { action, supportedShells } from "./commands/root.js";
8
9
  import { getVersion } from "./utils/version.js";
9
10
  const program = new Command();
@@ -17,4 +18,5 @@ program
17
18
  .option("-d, --duration <duration>", "duration of the autocomplete session, supported durations: single, session", "session")
18
19
  .action(action);
19
20
  program.addCommand(bind);
21
+ program.addCommand(uninstall);
20
22
  program.parse();
@@ -8,6 +8,7 @@ let uiResult = "";
8
8
  function UI() {
9
9
  const { exit } = useApp();
10
10
  const [selectionIdx, setSelectionIdx] = useState(0);
11
+ const [loaded, setLoaded] = useState(false);
11
12
  const [availableShells, setAvailableShells] = useState([]);
12
13
  useEffect(() => {
13
14
  availableBindings().then((bindings) => {
@@ -15,6 +16,7 @@ function UI() {
15
16
  exit();
16
17
  }
17
18
  setAvailableShells(bindings);
19
+ setLoaded(true);
18
20
  });
19
21
  }, []);
20
22
  useInput(async (_, key) => {
@@ -45,12 +47,15 @@ function UI() {
45
47
  " ",
46
48
  shell));
47
49
  }),
48
- supportedShells
49
- .filter((s) => !availableShells.includes(s))
50
- .map((shell, idx) => (React.createElement(Text, { color: "gray", key: idx },
51
- " ",
52
- shell,
53
- " (already bound)"))))));
50
+ loaded
51
+ ? supportedShells
52
+ .filter((s) => !availableShells.includes(s))
53
+ .map((shell, idx) => (React.createElement(Text, { color: "gray", key: idx },
54
+ " ",
55
+ shell,
56
+ " (already bound)")))
57
+ : null,
58
+ !loaded ? React.createElement(Text, null, "Loading...") : null)));
54
59
  }
55
60
  export const render = async () => {
56
61
  const { waitUntilExit } = inkRender(React.createElement(UI, null));
@@ -0,0 +1,11 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import chalk from "chalk";
4
+ import { unbindAll, deleteConfigFolder } from "../utils/bindings.js";
5
+ export const render = async () => {
6
+ await unbindAll();
7
+ process.stdout.write(chalk.green("✓") + " successfully uninstalled all existing bindings \n");
8
+ deleteConfigFolder();
9
+ process.stdout.write(chalk.green("✓") + " successfully deleted the .inshellisense config folder \n");
10
+ process.stdout.write(chalk.magenta("•") + " to complete the uninstall, run the the command: " + chalk.underline(chalk.cyan("npm uninstall -g @microsoft/inshellisense")) + "\n");
11
+ };
@@ -6,6 +6,9 @@ import fsAsync from "node:fs/promises";
6
6
  import fs from "node:fs";
7
7
  import process from "node:process";
8
8
  import url from "node:url";
9
+ import { exec } from "node:child_process";
10
+ import util from "node:util";
11
+ const execAsync = util.promisify(exec);
9
12
  const __filename = url.fileURLToPath(import.meta.url);
10
13
  const __dirname = path.dirname(__filename);
11
14
  const cacheFolder = ".inshellisense";
@@ -17,7 +20,7 @@ export var Shell;
17
20
  Shell["Zsh"] = "zsh";
18
21
  Shell["Fish"] = "fish";
19
22
  })(Shell || (Shell = {}));
20
- export const supportedShells = [Shell.Bash, Shell.Powershell, Shell.Pwsh, Shell.Zsh, Shell.Fish];
23
+ export const supportedShells = [Shell.Bash, process.platform == "win32" ? Shell.Powershell : null, Shell.Pwsh, Shell.Zsh, Shell.Fish].filter((shell) => shell != null);
21
24
  const bashScriptCommand = () => {
22
25
  return `[ -f ~/${cacheFolder}/key-bindings.bash ] && source ~/${cacheFolder}/key-bindings.bash`;
23
26
  };
@@ -35,16 +38,13 @@ const pwshScriptCommand = () => {
35
38
  const bindingsPath = path.join(os.homedir(), cacheFolder, "key-bindings-pwsh.ps1");
36
39
  return `if(Test-Path '${bindingsPath}' -PathType Leaf){. ${bindingsPath}}`;
37
40
  };
38
- const pwshConfigPath = () => {
39
- switch (process.platform) {
40
- case "win32":
41
- return path.join(os.homedir(), "Documents", "Powershell", "Microsoft.PowerShell_profile.ps1");
42
- case "linux":
43
- case "darwin":
44
- return path.join(os.homedir(), ".config", "powershell", "Microsoft.PowerShell_profile.ps1");
45
- default:
46
- throw new Error("Unsupported platform");
47
- }
41
+ const pwshConfigPath = async () => {
42
+ const { stdout } = await execAsync("echo $profile", { shell: "pwsh" });
43
+ return stdout.trim();
44
+ };
45
+ const powershellConfigPath = async () => {
46
+ const { stdout } = await execAsync("echo $profile", { shell: "powershell" });
47
+ return stdout.trim();
48
48
  };
49
49
  export const availableBindings = async () => {
50
50
  const cliConfigPath = path.join(os.homedir(), cacheFolder);
@@ -82,27 +82,102 @@ export const availableBindings = async () => {
82
82
  bindings.push(Shell.Fish);
83
83
  }
84
84
  }
85
- const powershellConfigPath = path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1");
86
- if (!fs.existsSync(powershellConfigPath)) {
87
- bindings.push(Shell.Powershell);
88
- }
89
- else {
90
- const powershellConfigContent = fsAsync.readFile(powershellConfigPath, { encoding: "utf-8" });
91
- if (!(await powershellConfigContent).includes(powershellScriptCommand())) {
85
+ const powershellResolvedConfigPath = await powershellConfigPath();
86
+ if (process.platform == "win32") {
87
+ if (!fs.existsSync(powershellResolvedConfigPath)) {
92
88
  bindings.push(Shell.Powershell);
93
89
  }
90
+ else {
91
+ const powershellConfigContent = fsAsync.readFile(powershellResolvedConfigPath, { encoding: "utf-8" });
92
+ if (!(await powershellConfigContent).includes(powershellScriptCommand())) {
93
+ bindings.push(Shell.Powershell);
94
+ }
95
+ }
94
96
  }
95
- if (!fs.existsSync(pwshConfigPath())) {
97
+ const pwshResolvedConfigPath = await pwshConfigPath();
98
+ if (!fs.existsSync(pwshResolvedConfigPath)) {
96
99
  bindings.push(Shell.Pwsh);
97
100
  }
98
101
  else {
99
- const pwshConfigContent = fsAsync.readFile(pwshConfigPath(), { encoding: "utf-8" });
102
+ const pwshConfigContent = fsAsync.readFile(pwshResolvedConfigPath, { encoding: "utf-8" });
100
103
  if (!(await pwshConfigContent).includes(pwshScriptCommand())) {
101
104
  bindings.push(Shell.Pwsh);
102
105
  }
103
106
  }
104
107
  return bindings;
105
108
  };
109
+ export const unbindAll = async () => {
110
+ try {
111
+ const bashConfigPath = path.join(os.homedir(), ".bashrc");
112
+ const bashConfig = (await fsAsync.readFile(bashConfigPath)).toString();
113
+ if (bashConfig.includes(bashScriptCommand())) {
114
+ const unboundBashConfig = bashConfig.toString().replace(bashScriptCommand(), "");
115
+ await fsAsync.writeFile(bashConfigPath, unboundBashConfig);
116
+ }
117
+ }
118
+ catch {
119
+ /* empty */
120
+ }
121
+ try {
122
+ const zshConfigPath = path.join(os.homedir(), ".zshrc");
123
+ const zshConfig = (await fsAsync.readFile(zshConfigPath)).toString();
124
+ if (zshConfig.includes(zshScriptCommand())) {
125
+ const unboundZshConfig = zshConfig.toString().replace(zshScriptCommand(), "");
126
+ await fsAsync.writeFile(zshConfigPath, unboundZshConfig);
127
+ }
128
+ }
129
+ catch {
130
+ /* empty */
131
+ }
132
+ try {
133
+ const fishConfigPath = path.join(os.homedir(), ".config", "fish", "config.fish");
134
+ const fishConfig = (await fsAsync.readFile(fishConfigPath)).toString();
135
+ if (fishConfig.includes(fishScriptCommand())) {
136
+ const unboundFishConfig = fishConfig.toString().replace(fishScriptCommand(), "");
137
+ await fsAsync.writeFile(fishConfigPath, unboundFishConfig);
138
+ }
139
+ }
140
+ catch {
141
+ /* empty */
142
+ }
143
+ try {
144
+ const powershellResolvedConfigPath = await powershellConfigPath();
145
+ const powershellConfig = (await fsAsync.readFile(powershellResolvedConfigPath)).toString();
146
+ if (powershellConfig.includes(powershellScriptCommand())) {
147
+ const unboundPowershellConfig = powershellConfig.toString().replace(powershellScriptCommand(), "");
148
+ await fsAsync.writeFile(powershellResolvedConfigPath, unboundPowershellConfig);
149
+ }
150
+ }
151
+ catch {
152
+ /* empty */
153
+ }
154
+ try {
155
+ const pwshResolvedConfigPath = await pwshConfigPath();
156
+ const pwshConfig = (await fsAsync.readFile(pwshResolvedConfigPath)).toString();
157
+ if (pwshConfig.includes(pwshScriptCommand())) {
158
+ const unboundPwshConfig = pwshConfig.toString().replace(pwshScriptCommand(), "");
159
+ await fsAsync.writeFile(pwshResolvedConfigPath, unboundPwshConfig);
160
+ }
161
+ }
162
+ catch {
163
+ /* empty */
164
+ }
165
+ };
166
+ export const deleteConfigFolder = async () => {
167
+ const cliConfigPath = path.join(os.homedir(), cacheFolder);
168
+ if (fs.existsSync(cliConfigPath)) {
169
+ fs.rmSync(cliConfigPath, { recursive: true });
170
+ }
171
+ };
172
+ const safeAppendFile = async (filepath, data) => {
173
+ if (!fs.existsSync(filepath)) {
174
+ await fsAsync.mkdir(path.dirname(filepath), { recursive: true });
175
+ await fsAsync.writeFile(filepath, data);
176
+ }
177
+ else {
178
+ await fsAsync.appendFile(filepath, data);
179
+ }
180
+ };
106
181
  export const bind = async (shell) => {
107
182
  const cliConfigPath = path.join(os.homedir(), cacheFolder);
108
183
  if (!fs.existsSync(cliConfigPath)) {
@@ -111,32 +186,29 @@ export const bind = async (shell) => {
111
186
  switch (shell) {
112
187
  case Shell.Bash: {
113
188
  const bashConfigPath = path.join(os.homedir(), ".bashrc");
114
- await fsAsync.appendFile(bashConfigPath, `\n${bashScriptCommand()}`);
189
+ await safeAppendFile(bashConfigPath, `\n${bashScriptCommand()}`);
115
190
  await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.bash"), path.join(os.homedir(), cacheFolder, "key-bindings.bash"));
116
191
  break;
117
192
  }
118
193
  case Shell.Zsh: {
119
194
  const zshConfigPath = path.join(os.homedir(), ".zshrc");
120
- await fsAsync.appendFile(zshConfigPath, `\n${zshScriptCommand()}`);
195
+ await safeAppendFile(zshConfigPath, `\n${zshScriptCommand()}`);
121
196
  await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.zsh"), path.join(os.homedir(), cacheFolder, "key-bindings.zsh"));
122
197
  break;
123
198
  }
124
199
  case Shell.Fish: {
125
- const fishConfigDirectory = path.join(os.homedir(), ".config", "fish");
126
- const fishConfigPath = path.join(fishConfigDirectory, "config.fish");
127
- await fsAsync.mkdir(fishConfigDirectory, { recursive: true });
128
- await fsAsync.appendFile(fishConfigPath, `\n${fishScriptCommand()}`);
200
+ const fishConfigPath = path.join(os.homedir(), ".config", "fish", "config.fish");
201
+ await safeAppendFile(fishConfigPath, `\n${fishScriptCommand()}`);
129
202
  await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.fish"), path.join(os.homedir(), cacheFolder, "key-bindings.fish"));
130
203
  break;
131
204
  }
132
205
  case Shell.Powershell: {
133
- const powershellConfigPath = path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1");
134
- await fsAsync.appendFile(powershellConfigPath, `\n${powershellScriptCommand()}`);
206
+ await safeAppendFile(await powershellConfigPath(), `\n${powershellScriptCommand()}`);
135
207
  await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings-powershell.ps1"), path.join(os.homedir(), cacheFolder, "key-bindings-powershell.ps1"));
136
208
  break;
137
209
  }
138
210
  case Shell.Pwsh: {
139
- await fsAsync.appendFile(pwshConfigPath(), `\n${pwshScriptCommand()}`);
211
+ await safeAppendFile(await pwshConfigPath(), `\n${pwshScriptCommand()}`);
140
212
  await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings-pwsh.ps1"), path.join(os.homedir(), cacheFolder, "key-bindings-pwsh.ps1"));
141
213
  break;
142
214
  }
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "@microsoft/inshellisense",
3
- "version": "0.0.1-rc.1",
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
- },
23
- "repository": {
24
- "type": "git",
25
- "url": "git+https://github.com/microsoft/inshellisense.git"
26
- },
27
- "author": {
28
- "name": "Microsoft Corporation"
29
- },
30
- "license": "MIT",
31
- "bugs": {
32
- "url": "https://github.com/microsoft/inshellisense/issues"
33
- },
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"
42
- },
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"
58
- }
59
- }
1
+ {
2
+ "name": "@microsoft/inshellisense",
3
+ "version": "0.0.1-rc.2",
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
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/microsoft/inshellisense.git"
26
+ },
27
+ "author": {
28
+ "name": "Microsoft Corporation"
29
+ },
30
+ "license": "MIT",
31
+ "bugs": {
32
+ "url": "https://github.com/microsoft/inshellisense/issues"
33
+ },
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"
42
+ },
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"
58
+ }
59
+ }
@@ -1,27 +1,27 @@
1
- Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
2
- $command = $null
3
- [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
4
-
5
- $oldPrompt = $function:prompt
6
- function prompt { "`r" }
7
- [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
8
- $prompt = $oldPrompt
9
-
10
- [Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
11
- [Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
12
- [Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
13
- [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
14
-
15
- $inshellisense = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\inshellisense\build\index.js"
16
- if ($command) {
17
- Start-Process -NoNewWindow -Wait "node" "$inshellisense -c $command -s powershell"
18
- }
19
- else {
20
- Start-Process -NoNewWindow -Wait "node" "$inshellisense -s powershell"
21
- }
22
-
23
- $executedCommand = node $inshellisense --history
24
- if ($executedCommand) {
25
- [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
26
- }
1
+ Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
2
+ $command = $null
3
+ [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
4
+
5
+ $oldPrompt = $function:prompt
6
+ function prompt { "`r" }
7
+ [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
8
+ $prompt = $oldPrompt
9
+
10
+ [Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
11
+ [Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
12
+ [Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
13
+ [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
14
+
15
+ $inshellisense = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\inshellisense\build\index.js"
16
+ if ($command) {
17
+ Start-Process -NoNewWindow -Wait "node" "$inshellisense -c $command -s powershell"
18
+ }
19
+ else {
20
+ Start-Process -NoNewWindow -Wait "node" "$inshellisense -s powershell"
21
+ }
22
+
23
+ $executedCommand = node $inshellisense --history
24
+ if ($executedCommand) {
25
+ [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
26
+ }
27
27
  }
@@ -1,27 +1,27 @@
1
- Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
2
- $command = $null
3
- [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
4
-
5
- $oldPrompt = $function:prompt
6
- function prompt { "`r" }
7
- [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
8
- $prompt = $oldPrompt
9
-
10
- [Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
11
- [Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
12
- [Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
13
-
14
- $inshellisense = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\inshellisense\build\index.js"
15
- if ($command) {
16
- Start-Process -NoNewWindow -Wait "node" "$inshellisense -c $command -s pwsh"
17
- }
18
- else {
19
- Start-Process -NoNewWindow -Wait "node" "$inshellisense -s pwsh"
20
- }
21
-
22
- $executedCommand = node $inshellisense --history
23
- if ($executedCommand) {
24
- [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
25
- }
26
- [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
1
+ Set-PSReadLineKeyHandler -Chord 'Ctrl+a' -ScriptBlock {
2
+ $command = $null
3
+ [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$command, [ref]$null)
4
+
5
+ $oldPrompt = $function:prompt
6
+ function prompt { "`r" }
7
+ [Microsoft.PowerShell.PSConsoleReadLine]::InvokePrompt()
8
+ $prompt = $oldPrompt
9
+
10
+ [Microsoft.PowerShell.PSConsoleReadLine]::ClearKillRing()
11
+ [Microsoft.PowerShell.PSConsoleReadLine]::BeginningOfLine()
12
+ [Microsoft.PowerShell.PSConsoleReadLine]::KillLine()
13
+
14
+ $inshellisense = "$env:USERPROFILE\AppData\Roaming\npm\node_modules\@microsoft\inshellisense\build\index.js"
15
+ if ($command) {
16
+ Start-Process -NoNewWindow -Wait "node" "$inshellisense -c $command -s pwsh"
17
+ }
18
+ else {
19
+ Start-Process -NoNewWindow -Wait "node" "$inshellisense -s pwsh"
20
+ }
21
+
22
+ $executedCommand = node $inshellisense --history
23
+ if ($executedCommand) {
24
+ [Microsoft.PowerShell.PSConsoleReadLine]::AddToHistory($executedCommand)
25
+ }
26
+ [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine()
27
27
  }
@@ -1,7 +1,7 @@
1
- __inshellisense__() {
2
- inshellisense -c "$READLINE_LINE" -s bash
3
- history -s $(inshellisense --history)
4
- READLINE_LINE=
5
- }
6
-
1
+ __inshellisense__() {
2
+ inshellisense -c "$READLINE_LINE" -s bash
3
+ history -s $(inshellisense --history)
4
+ READLINE_LINE=
5
+ }
6
+
7
7
  bind -x '"\C-a": __inshellisense__'
@@ -1,8 +1,8 @@
1
- function inshellisense-widget -d "Activate autocomplete"
2
- inshellisense -c (commandline -b) -s fish
3
- commandline -r ''
4
- commandline -f repaint
5
- # TODO: add support for history insertion
6
- end
7
-
1
+ function inshellisense-widget -d "Activate autocomplete"
2
+ inshellisense -c (commandline -b) -s fish
3
+ commandline -r ''
4
+ commandline -f repaint
5
+ # TODO: add support for history insertion
6
+ end
7
+
8
8
  bind \ca inshellisense-widget
@@ -1,10 +1,10 @@
1
- __inshellisense__() {
2
- input=$LBUFFER
3
- LBUFFER=
4
- inshellisense -c "$input" -s zsh < $TTY
5
- print -s $(inshellisense --history)
6
- zle reset-prompt
7
- }
8
-
9
- zle -N __inshellisense __inshellisense__
1
+ __inshellisense__() {
2
+ input=$LBUFFER
3
+ LBUFFER=
4
+ inshellisense -c "$input" -s zsh < $TTY
5
+ print -s $(inshellisense --history)
6
+ zle reset-prompt
7
+ }
8
+
9
+ zle -N __inshellisense __inshellisense__
10
10
  bindkey '^A' __inshellisense