@microsoft/inshellisense 0.0.1-rc.1

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.
@@ -0,0 +1,21 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import os from "node:os";
4
+ import path from "node:path";
5
+ import fsAsync from "node:fs/promises";
6
+ import fs from "node:fs";
7
+ const cacheFolder = ".inshellisense";
8
+ const folderPath = path.join(os.homedir(), cacheFolder);
9
+ const cachePath = path.join(os.homedir(), cacheFolder, "inshellisense.cache");
10
+ export const saveCommand = async (command) => {
11
+ if (!fs.existsSync(folderPath)) {
12
+ await fsAsync.mkdir(folderPath);
13
+ }
14
+ await fsAsync.writeFile(cachePath, command.map((c, idx) => `${idx.toString().padStart(5)} ${c}`).join("\n"));
15
+ };
16
+ export const loadCommand = async () => {
17
+ if (!fs.existsSync(folderPath)) {
18
+ await fsAsync.mkdir(folderPath);
19
+ }
20
+ return fsAsync.readFile(cachePath, { encoding: "utf-8" });
21
+ };
@@ -0,0 +1,13 @@
1
+ // Copyright (c) Microsoft Corporation.
2
+ // Licensed under the MIT License.
3
+ import url from "node:url";
4
+ import path from "node:path";
5
+ import fsAsync from "node:fs/promises";
6
+ const __filename = url.fileURLToPath(import.meta.url);
7
+ const __dirname = path.dirname(__filename);
8
+ export const getVersion = async () => {
9
+ const packageJsonPath = path.join(__dirname, "..", "..", "package.json");
10
+ const packageJson = await fsAsync.readFile(packageJsonPath, { encoding: "utf-8" });
11
+ const packageJsonParsed = JSON.parse(packageJson);
12
+ return packageJsonParsed.version;
13
+ };
package/package.json ADDED
@@ -0,0 +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
+ }
@@ -0,0 +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
+ }
27
+ }
@@ -0,0 +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()
27
+ }
@@ -0,0 +1,7 @@
1
+ __inshellisense__() {
2
+ inshellisense -c "$READLINE_LINE" -s bash
3
+ history -s $(inshellisense --history)
4
+ READLINE_LINE=
5
+ }
6
+
7
+ bind -x '"\C-a": __inshellisense__'
@@ -0,0 +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
+
8
+ bind \ca inshellisense-widget
@@ -0,0 +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__
10
+ bindkey '^A' __inshellisense