@microsoft/inshellisense 0.0.1-rc.4 → 0.0.1-rc.5
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/README.md +4 -8
- package/build/commands/root.js +9 -29
- package/build/commands/uninstall.js +1 -1
- package/build/index.js +1 -6
- package/build/isterm/commandManager.js +212 -0
- package/build/isterm/index.js +4 -0
- package/build/isterm/pty.js +217 -0
- package/build/runtime/template.js +1 -1
- package/build/ui/input.js +7 -53
- package/build/ui/suggestionManager.js +119 -0
- package/build/ui/ui-root.js +109 -64
- package/build/ui/ui-uninstall.js +1 -3
- package/build/ui/utils.js +41 -0
- package/build/utils/ansi.js +55 -0
- package/build/utils/config.js +68 -0
- package/build/utils/log.js +22 -0
- package/build/utils/shell.js +68 -1
- package/package.json +9 -4
- package/shell/shellIntegration-env.zsh +9 -0
- package/shell/shellIntegration-login.zsh +4 -0
- package/shell/shellIntegration-profile.zsh +4 -0
- package/shell/shellIntegration-rc.zsh +19 -0
- package/shell/shellIntegration.bash +31 -0
- package/shell/shellIntegration.fish +6 -0
- package/shell/shellIntegration.ps1 +8 -0
- package/build/commands/bind.js +0 -12
- package/build/ui/suggestions.js +0 -84
- package/build/ui/ui-bind.js +0 -69
- package/build/ui/ui-init.js +0 -44
- package/build/utils/bindings.js +0 -236
- package/build/utils/cache.js +0 -21
- package/shell/key-bindings-powershell.ps1 +0 -27
- package/shell/key-bindings-pwsh.ps1 +0 -27
- package/shell/key-bindings.bash +0 -7
- package/shell/key-bindings.fish +0 -8
- package/shell/key-bindings.zsh +0 -10
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
if [ -r ~/.bashrc ]; then
|
|
2
|
+
. ~/.bashrc
|
|
3
|
+
fi
|
|
4
|
+
if [ -r /etc/profile ]; then
|
|
5
|
+
. /etc/profile
|
|
6
|
+
fi
|
|
7
|
+
if [ -r ~/.bash_profile ]; then
|
|
8
|
+
. ~/.bash_profile
|
|
9
|
+
elif [ -r ~/.bash_login ]; then
|
|
10
|
+
. ~/.bash_login
|
|
11
|
+
elif [ -r ~/.profile ]; then
|
|
12
|
+
. ~/.profile
|
|
13
|
+
fi
|
|
14
|
+
|
|
15
|
+
__is_prompt_start() {
|
|
16
|
+
builtin printf '\e]6973;PS\a'
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
__is_prompt_end() {
|
|
20
|
+
builtin printf '\e]6973;PE\a'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
__is_update_prompt() {
|
|
24
|
+
if [[ "$__is_custom_PS1" == "" || "$__is_custom_PS1" != "$PS1" ]]; then
|
|
25
|
+
__is_original_PS1=$PS1
|
|
26
|
+
__is_custom_PS1="\[$(__is_prompt_start)\]$__is_original_PS1\[$(__is_prompt_end)\]"
|
|
27
|
+
export PS1="$__is_custom_PS1"
|
|
28
|
+
fi
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
__is_update_prompt
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
function __is_copy_function; functions $argv[1] | sed "s/^function $argv[1]/function $argv[2]/" | source; end
|
|
2
|
+
function __is_prompt_start; printf '\e]6973;PS\a'; end
|
|
3
|
+
function __is_prompt_end; printf '\e]6973;PE\a'; end
|
|
4
|
+
|
|
5
|
+
__is_copy_function fish_prompt is_user_prompt
|
|
6
|
+
function fish_prompt; printf (__is_prompt_start); printf (is_user_prompt); printf (__is_prompt_end); end
|
package/build/commands/bind.js
DELETED
|
@@ -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;
|
package/build/ui/suggestions.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import React, { useState, useCallback, useEffect } from "react";
|
|
4
|
-
import { Text, useInput, Box, measureElement } from "ink";
|
|
5
|
-
import wrapAnsi from "wrap-ansi";
|
|
6
|
-
const MaxSuggestions = 5;
|
|
7
|
-
const SuggestionWidth = 40;
|
|
8
|
-
const DescriptionWidth = 30;
|
|
9
|
-
const DescriptionMaxHeight = 6;
|
|
10
|
-
const BorderWidth = 2;
|
|
11
|
-
const ActiveSuggestionBackgroundColor = "#7D56F4";
|
|
12
|
-
function Description({ description }) {
|
|
13
|
-
wrapAnsi(description, DescriptionWidth, { hard: true });
|
|
14
|
-
if (description.length !== 0) {
|
|
15
|
-
return (React.createElement(Box, { flexDirection: "column" },
|
|
16
|
-
React.createElement(Box, { borderStyle: "single", width: DescriptionWidth },
|
|
17
|
-
React.createElement(Text, null, truncateDescription(description, DescriptionMaxHeight)))));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function truncateDescription(description, maxHeight) {
|
|
21
|
-
const wrappedText = wrapAnsi(description, DescriptionWidth - BorderWidth, {
|
|
22
|
-
trim: false,
|
|
23
|
-
hard: true,
|
|
24
|
-
});
|
|
25
|
-
const lines = wrappedText.split("\n");
|
|
26
|
-
const truncatedLines = lines.slice(0, maxHeight);
|
|
27
|
-
if (lines.length > maxHeight) {
|
|
28
|
-
truncatedLines[maxHeight - 1] = [...truncatedLines[maxHeight - 1]].slice(0, -1).join("") + "…";
|
|
29
|
-
}
|
|
30
|
-
return truncatedLines.join("\n");
|
|
31
|
-
}
|
|
32
|
-
function SuggestionList({ suggestions, activeSuggestionIdx }) {
|
|
33
|
-
return (React.createElement(Box, { flexDirection: "column" },
|
|
34
|
-
React.createElement(Box, { borderStyle: "single", width: SuggestionWidth, flexDirection: "column" }, suggestions
|
|
35
|
-
.map((suggestion, idx) => {
|
|
36
|
-
const bgColor = idx === activeSuggestionIdx ? ActiveSuggestionBackgroundColor : undefined;
|
|
37
|
-
return (React.createElement(Box, { key: idx },
|
|
38
|
-
React.createElement(Text, { backgroundColor: bgColor, wrap: "truncate-end" }, `${suggestion.icon} ${suggestion.name}`.padEnd(SuggestionWidth - BorderWidth, " "))));
|
|
39
|
-
})
|
|
40
|
-
.filter((node) => node !== undefined))));
|
|
41
|
-
}
|
|
42
|
-
export default function Suggestions({ leftPadding, setActiveSuggestion, suggestions, }) {
|
|
43
|
-
const [activeSuggestionIndex, setActiveSuggestionIndex] = useState(0);
|
|
44
|
-
const [windowWidth, setWindowWidth] = useState(500);
|
|
45
|
-
const page = Math.floor(activeSuggestionIndex / MaxSuggestions) + 1;
|
|
46
|
-
const pagedSuggestions = suggestions.filter((_, idx) => idx < page * MaxSuggestions && idx >= (page - 1) * MaxSuggestions);
|
|
47
|
-
const activePagedSuggestionIndex = activeSuggestionIndex % MaxSuggestions;
|
|
48
|
-
const activeDescription = pagedSuggestions.at(activePagedSuggestionIndex)?.description || "";
|
|
49
|
-
const wrappedPadding = leftPadding % windowWidth;
|
|
50
|
-
const maxPadding = activeDescription.length !== 0 ? windowWidth - SuggestionWidth - DescriptionWidth : windowWidth - SuggestionWidth;
|
|
51
|
-
const swapDescription = wrappedPadding > maxPadding;
|
|
52
|
-
const swappedPadding = swapDescription ? Math.max(wrappedPadding - DescriptionWidth, 0) : wrappedPadding;
|
|
53
|
-
const clampedLeftPadding = Math.min(Math.min(wrappedPadding, swappedPadding), maxPadding);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
setActiveSuggestion(suggestions[activeSuggestionIndex]);
|
|
56
|
-
}, [activeSuggestionIndex, suggestions]);
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
if (suggestions.length <= activeSuggestionIndex) {
|
|
59
|
-
setActiveSuggestionIndex(Math.max(suggestions.length - 1, 0));
|
|
60
|
-
}
|
|
61
|
-
}, [suggestions]);
|
|
62
|
-
useInput((_, key) => {
|
|
63
|
-
if (key.upArrow) {
|
|
64
|
-
setActiveSuggestionIndex(Math.max(0, activeSuggestionIndex - 1));
|
|
65
|
-
}
|
|
66
|
-
if (key.downArrow) {
|
|
67
|
-
setActiveSuggestionIndex(Math.min(activeSuggestionIndex + 1, suggestions.length - 1));
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
const measureRef = useCallback((node) => {
|
|
71
|
-
if (node !== null) {
|
|
72
|
-
const { width } = measureElement(node);
|
|
73
|
-
setWindowWidth(width);
|
|
74
|
-
}
|
|
75
|
-
}, []);
|
|
76
|
-
if (suggestions.length === 0)
|
|
77
|
-
return React.createElement(React.Fragment, null);
|
|
78
|
-
return (React.createElement(Box, { ref: measureRef },
|
|
79
|
-
React.createElement(Box, { paddingLeft: clampedLeftPadding }, swapDescription ? (React.createElement(React.Fragment, null,
|
|
80
|
-
React.createElement(Description, { description: activeDescription }),
|
|
81
|
-
React.createElement(SuggestionList, { suggestions: pagedSuggestions, activeSuggestionIdx: activePagedSuggestionIndex }))) : (React.createElement(React.Fragment, null,
|
|
82
|
-
React.createElement(SuggestionList, { suggestions: pagedSuggestions, activeSuggestionIdx: activePagedSuggestionIndex }),
|
|
83
|
-
React.createElement(Description, { description: activeDescription }))))));
|
|
84
|
-
}
|
package/build/ui/ui-bind.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import React, { useEffect, useState } from "react";
|
|
4
|
-
import { Box, Text, render as inkRender, useInput, useApp } from "ink";
|
|
5
|
-
import chalk from "chalk";
|
|
6
|
-
import { availableBindings, bind, supportedShells } from "../utils/bindings.js";
|
|
7
|
-
let uiResult = "";
|
|
8
|
-
function UI() {
|
|
9
|
-
const { exit } = useApp();
|
|
10
|
-
const [selectionIdx, setSelectionIdx] = useState(0);
|
|
11
|
-
const [loaded, setLoaded] = useState(false);
|
|
12
|
-
const [availableShells, setAvailableShells] = useState([]);
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
availableBindings().then((bindings) => {
|
|
15
|
-
if (bindings.length == 0) {
|
|
16
|
-
exit();
|
|
17
|
-
}
|
|
18
|
-
setAvailableShells(bindings);
|
|
19
|
-
setLoaded(true);
|
|
20
|
-
});
|
|
21
|
-
}, []);
|
|
22
|
-
useInput(async (_, key) => {
|
|
23
|
-
if (key.upArrow) {
|
|
24
|
-
setSelectionIdx(Math.max(0, selectionIdx - 1));
|
|
25
|
-
}
|
|
26
|
-
else if (key.downArrow) {
|
|
27
|
-
setSelectionIdx(Math.min(availableShells.length - 1, selectionIdx + 1));
|
|
28
|
-
}
|
|
29
|
-
else if (key.return) {
|
|
30
|
-
await bind(availableShells[selectionIdx]);
|
|
31
|
-
uiResult = availableShells[selectionIdx];
|
|
32
|
-
exit();
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
return (React.createElement(Box, { flexDirection: "column" },
|
|
36
|
-
React.createElement(Box, null,
|
|
37
|
-
React.createElement(Text, { bold: true }, "Select your desired shell for keybinding creation")),
|
|
38
|
-
React.createElement(Box, { flexDirection: "column" },
|
|
39
|
-
availableShells.map((shell, idx) => {
|
|
40
|
-
if (idx == selectionIdx) {
|
|
41
|
-
return (React.createElement(Text, { color: "cyan", underline: true, key: idx },
|
|
42
|
-
">",
|
|
43
|
-
" ",
|
|
44
|
-
shell));
|
|
45
|
-
}
|
|
46
|
-
return (React.createElement(Text, { key: idx },
|
|
47
|
-
" ",
|
|
48
|
-
shell));
|
|
49
|
-
}),
|
|
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)));
|
|
59
|
-
}
|
|
60
|
-
export const render = async () => {
|
|
61
|
-
const { waitUntilExit } = inkRender(React.createElement(UI, null));
|
|
62
|
-
await waitUntilExit();
|
|
63
|
-
if (uiResult.length !== 0) {
|
|
64
|
-
process.stdout.write("\n" + chalk.green("✓") + " successfully created new bindings \n");
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
process.stdout.write("\n");
|
|
68
|
-
}
|
|
69
|
-
};
|
package/build/ui/ui-init.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import React, { useState } from "react";
|
|
4
|
-
import { Box, Text, render, useApp, useInput } from "ink";
|
|
5
|
-
import { supportedShells } from "../utils/bindings.js";
|
|
6
|
-
let uiResult = undefined;
|
|
7
|
-
function UI() {
|
|
8
|
-
const { exit } = useApp();
|
|
9
|
-
const [selectionIdx, setSelectionIdx] = useState(0);
|
|
10
|
-
const [exited, setExited] = useState(false);
|
|
11
|
-
useInput(async (_, key) => {
|
|
12
|
-
if (key.upArrow) {
|
|
13
|
-
setSelectionIdx(Math.max(0, selectionIdx - 1));
|
|
14
|
-
}
|
|
15
|
-
else if (key.downArrow) {
|
|
16
|
-
setSelectionIdx(Math.min(supportedShells.length - 1, selectionIdx + 1));
|
|
17
|
-
}
|
|
18
|
-
else if (key.return) {
|
|
19
|
-
uiResult = supportedShells[selectionIdx];
|
|
20
|
-
setExited(true);
|
|
21
|
-
setTimeout(exit, 0);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return (React.createElement(React.Fragment, null, exited ? null : (React.createElement(Box, { flexDirection: "column" },
|
|
25
|
-
React.createElement(Box, null,
|
|
26
|
-
React.createElement(Text, { bold: true }, "Select your desired shell")),
|
|
27
|
-
React.createElement(Box, { flexDirection: "column" }, supportedShells.map((shell, idx) => {
|
|
28
|
-
if (idx == selectionIdx) {
|
|
29
|
-
return (React.createElement(Text, { color: "cyan", underline: true, key: idx },
|
|
30
|
-
">",
|
|
31
|
-
" ",
|
|
32
|
-
shell));
|
|
33
|
-
}
|
|
34
|
-
return (React.createElement(Text, { key: idx },
|
|
35
|
-
" ",
|
|
36
|
-
shell));
|
|
37
|
-
}))))));
|
|
38
|
-
}
|
|
39
|
-
export const initRender = async () => {
|
|
40
|
-
uiResult = undefined;
|
|
41
|
-
const { waitUntilExit } = render(React.createElement(UI, null));
|
|
42
|
-
await waitUntilExit();
|
|
43
|
-
return uiResult;
|
|
44
|
-
};
|
package/build/utils/bindings.js
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
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
|
-
import process from "node:process";
|
|
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);
|
|
12
|
-
const __filename = url.fileURLToPath(import.meta.url);
|
|
13
|
-
const __dirname = path.dirname(__filename);
|
|
14
|
-
const cacheFolder = ".inshellisense";
|
|
15
|
-
export var Shell;
|
|
16
|
-
(function (Shell) {
|
|
17
|
-
Shell["Bash"] = "bash";
|
|
18
|
-
Shell["Powershell"] = "powershell";
|
|
19
|
-
Shell["Pwsh"] = "pwsh";
|
|
20
|
-
Shell["Zsh"] = "zsh";
|
|
21
|
-
Shell["Fish"] = "fish";
|
|
22
|
-
})(Shell || (Shell = {}));
|
|
23
|
-
export const supportedShells = [Shell.Bash, process.platform == "win32" ? Shell.Powershell : null, Shell.Pwsh, Shell.Zsh, Shell.Fish].filter((shell) => shell != null);
|
|
24
|
-
const bashScriptCommand = () => {
|
|
25
|
-
return `[ -f ~/${cacheFolder}/key-bindings.bash ] && source ~/${cacheFolder}/key-bindings.bash`;
|
|
26
|
-
};
|
|
27
|
-
const zshScriptCommand = () => {
|
|
28
|
-
return `[ -f ~/${cacheFolder}/key-bindings.zsh ] && source ~/${cacheFolder}/key-bindings.zsh`;
|
|
29
|
-
};
|
|
30
|
-
const fishScriptCommand = () => {
|
|
31
|
-
return `[ -f ~/${cacheFolder}/key-bindings.fish ] && source ~/${cacheFolder}/key-bindings.fish`;
|
|
32
|
-
};
|
|
33
|
-
const powershellScriptCommand = () => {
|
|
34
|
-
const bindingsPath = path.join(os.homedir(), cacheFolder, "key-bindings-powershell.ps1");
|
|
35
|
-
return `if(Test-Path '${bindingsPath}' -PathType Leaf){. ${bindingsPath}}`;
|
|
36
|
-
};
|
|
37
|
-
const pwshScriptCommand = () => {
|
|
38
|
-
const bindingsPath = path.join(os.homedir(), cacheFolder, "key-bindings-pwsh.ps1");
|
|
39
|
-
return `if(Test-Path '${bindingsPath}' -PathType Leaf){. ${bindingsPath}}`;
|
|
40
|
-
};
|
|
41
|
-
const pwshConfigPath = async () => {
|
|
42
|
-
try {
|
|
43
|
-
const { stdout } = await execAsync("echo $profile", { shell: "pwsh" });
|
|
44
|
-
return stdout.trim();
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
/* empty */
|
|
48
|
-
}
|
|
49
|
-
switch (process.platform) {
|
|
50
|
-
case "win32":
|
|
51
|
-
return path.join(os.homedir(), "Documents", "Powershell", "Microsoft.PowerShell_profile.ps1");
|
|
52
|
-
case "linux":
|
|
53
|
-
case "darwin":
|
|
54
|
-
return path.join(os.homedir(), ".config", "powershell", "Microsoft.PowerShell_profile.ps1");
|
|
55
|
-
default:
|
|
56
|
-
throw new Error("Unsupported platform");
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
const powershellConfigPath = async () => {
|
|
60
|
-
try {
|
|
61
|
-
const { stdout } = await execAsync("echo $profile", { shell: "powershell" });
|
|
62
|
-
return stdout.trim();
|
|
63
|
-
}
|
|
64
|
-
catch {
|
|
65
|
-
/* empty */
|
|
66
|
-
}
|
|
67
|
-
return path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1");
|
|
68
|
-
};
|
|
69
|
-
export const availableBindings = async () => {
|
|
70
|
-
const cliConfigPath = path.join(os.homedir(), cacheFolder);
|
|
71
|
-
if (!fs.existsSync(cliConfigPath)) {
|
|
72
|
-
await fsAsync.mkdir(cliConfigPath);
|
|
73
|
-
}
|
|
74
|
-
const bindings = [];
|
|
75
|
-
const bashConfigPath = path.join(os.homedir(), ".bashrc");
|
|
76
|
-
if (!fs.existsSync(bashConfigPath)) {
|
|
77
|
-
bindings.push(Shell.Bash);
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
const bashConfigContent = fsAsync.readFile(bashConfigPath, { encoding: "utf-8" });
|
|
81
|
-
if (!(await bashConfigContent).includes(bashScriptCommand())) {
|
|
82
|
-
bindings.push(Shell.Bash);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const zshConfigPath = path.join(os.homedir(), ".zshrc");
|
|
86
|
-
if (!fs.existsSync(zshConfigPath)) {
|
|
87
|
-
bindings.push(Shell.Zsh);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
const zshConfigContent = fsAsync.readFile(zshConfigPath, { encoding: "utf-8" });
|
|
91
|
-
if (!(await zshConfigContent).includes(zshScriptCommand())) {
|
|
92
|
-
bindings.push(Shell.Zsh);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const fishConfigPath = path.join(os.homedir(), ".config", "fish", "config.fish");
|
|
96
|
-
if (!fs.existsSync(fishConfigPath)) {
|
|
97
|
-
bindings.push(Shell.Fish);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
const fishConfigContent = fsAsync.readFile(fishConfigPath, { encoding: "utf-8" });
|
|
101
|
-
if (!(await fishConfigContent).includes(fishScriptCommand())) {
|
|
102
|
-
bindings.push(Shell.Fish);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
if (process.platform == "win32") {
|
|
106
|
-
const powershellResolvedConfigPath = await powershellConfigPath();
|
|
107
|
-
if (!fs.existsSync(powershellResolvedConfigPath)) {
|
|
108
|
-
bindings.push(Shell.Powershell);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
const powershellConfigContent = fsAsync.readFile(powershellResolvedConfigPath, { encoding: "utf-8" });
|
|
112
|
-
if (!(await powershellConfigContent).includes(powershellScriptCommand())) {
|
|
113
|
-
bindings.push(Shell.Powershell);
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
const pwshResolvedConfigPath = await pwshConfigPath();
|
|
118
|
-
if (!fs.existsSync(pwshResolvedConfigPath)) {
|
|
119
|
-
bindings.push(Shell.Pwsh);
|
|
120
|
-
}
|
|
121
|
-
else {
|
|
122
|
-
const pwshConfigContent = fsAsync.readFile(pwshResolvedConfigPath, { encoding: "utf-8" });
|
|
123
|
-
if (!(await pwshConfigContent).includes(pwshScriptCommand())) {
|
|
124
|
-
bindings.push(Shell.Pwsh);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return bindings;
|
|
128
|
-
};
|
|
129
|
-
export const unbindAll = async () => {
|
|
130
|
-
try {
|
|
131
|
-
const bashConfigPath = path.join(os.homedir(), ".bashrc");
|
|
132
|
-
const bashConfig = (await fsAsync.readFile(bashConfigPath)).toString();
|
|
133
|
-
if (bashConfig.includes(bashScriptCommand())) {
|
|
134
|
-
const unboundBashConfig = bashConfig.toString().replace(bashScriptCommand(), "");
|
|
135
|
-
await fsAsync.writeFile(bashConfigPath, unboundBashConfig);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
catch {
|
|
139
|
-
/* empty */
|
|
140
|
-
}
|
|
141
|
-
try {
|
|
142
|
-
const zshConfigPath = path.join(os.homedir(), ".zshrc");
|
|
143
|
-
const zshConfig = (await fsAsync.readFile(zshConfigPath)).toString();
|
|
144
|
-
if (zshConfig.includes(zshScriptCommand())) {
|
|
145
|
-
const unboundZshConfig = zshConfig.toString().replace(zshScriptCommand(), "");
|
|
146
|
-
await fsAsync.writeFile(zshConfigPath, unboundZshConfig);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
catch {
|
|
150
|
-
/* empty */
|
|
151
|
-
}
|
|
152
|
-
try {
|
|
153
|
-
const fishConfigPath = path.join(os.homedir(), ".config", "fish", "config.fish");
|
|
154
|
-
const fishConfig = (await fsAsync.readFile(fishConfigPath)).toString();
|
|
155
|
-
if (fishConfig.includes(fishScriptCommand())) {
|
|
156
|
-
const unboundFishConfig = fishConfig.toString().replace(fishScriptCommand(), "");
|
|
157
|
-
await fsAsync.writeFile(fishConfigPath, unboundFishConfig);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
catch {
|
|
161
|
-
/* empty */
|
|
162
|
-
}
|
|
163
|
-
try {
|
|
164
|
-
const powershellResolvedConfigPath = await powershellConfigPath();
|
|
165
|
-
const powershellConfig = (await fsAsync.readFile(powershellResolvedConfigPath)).toString();
|
|
166
|
-
if (powershellConfig.includes(powershellScriptCommand())) {
|
|
167
|
-
const unboundPowershellConfig = powershellConfig.toString().replace(powershellScriptCommand(), "");
|
|
168
|
-
await fsAsync.writeFile(powershellResolvedConfigPath, unboundPowershellConfig);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
catch {
|
|
172
|
-
/* empty */
|
|
173
|
-
}
|
|
174
|
-
try {
|
|
175
|
-
const pwshResolvedConfigPath = await pwshConfigPath();
|
|
176
|
-
const pwshConfig = (await fsAsync.readFile(pwshResolvedConfigPath)).toString();
|
|
177
|
-
if (pwshConfig.includes(pwshScriptCommand())) {
|
|
178
|
-
const unboundPwshConfig = pwshConfig.toString().replace(pwshScriptCommand(), "");
|
|
179
|
-
await fsAsync.writeFile(pwshResolvedConfigPath, unboundPwshConfig);
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
catch {
|
|
183
|
-
/* empty */
|
|
184
|
-
}
|
|
185
|
-
};
|
|
186
|
-
export const deleteConfigFolder = async () => {
|
|
187
|
-
const cliConfigPath = path.join(os.homedir(), cacheFolder);
|
|
188
|
-
if (fs.existsSync(cliConfigPath)) {
|
|
189
|
-
fs.rmSync(cliConfigPath, { recursive: true });
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
const safeAppendFile = async (filepath, data) => {
|
|
193
|
-
if (!fs.existsSync(filepath)) {
|
|
194
|
-
await fsAsync.mkdir(path.dirname(filepath), { recursive: true });
|
|
195
|
-
await fsAsync.writeFile(filepath, data);
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
await fsAsync.appendFile(filepath, data);
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
export const bind = async (shell) => {
|
|
202
|
-
const cliConfigPath = path.join(os.homedir(), cacheFolder);
|
|
203
|
-
if (!fs.existsSync(cliConfigPath)) {
|
|
204
|
-
await fsAsync.mkdir(cliConfigPath);
|
|
205
|
-
}
|
|
206
|
-
switch (shell) {
|
|
207
|
-
case Shell.Bash: {
|
|
208
|
-
const bashConfigPath = path.join(os.homedir(), ".bashrc");
|
|
209
|
-
await safeAppendFile(bashConfigPath, `\n${bashScriptCommand()}`);
|
|
210
|
-
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.bash"), path.join(os.homedir(), cacheFolder, "key-bindings.bash"));
|
|
211
|
-
break;
|
|
212
|
-
}
|
|
213
|
-
case Shell.Zsh: {
|
|
214
|
-
const zshConfigPath = path.join(os.homedir(), ".zshrc");
|
|
215
|
-
await safeAppendFile(zshConfigPath, `\n${zshScriptCommand()}`);
|
|
216
|
-
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.zsh"), path.join(os.homedir(), cacheFolder, "key-bindings.zsh"));
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
case Shell.Fish: {
|
|
220
|
-
const fishConfigPath = path.join(os.homedir(), ".config", "fish", "config.fish");
|
|
221
|
-
await safeAppendFile(fishConfigPath, `\n${fishScriptCommand()}`);
|
|
222
|
-
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.fish"), path.join(os.homedir(), cacheFolder, "key-bindings.fish"));
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
case Shell.Powershell: {
|
|
226
|
-
await safeAppendFile(await powershellConfigPath(), `\n${powershellScriptCommand()}`);
|
|
227
|
-
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings-powershell.ps1"), path.join(os.homedir(), cacheFolder, "key-bindings-powershell.ps1"));
|
|
228
|
-
break;
|
|
229
|
-
}
|
|
230
|
-
case Shell.Pwsh: {
|
|
231
|
-
await safeAppendFile(await pwshConfigPath(), `\n${pwshScriptCommand()}`);
|
|
232
|
-
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings-pwsh.ps1"), path.join(os.homedir(), cacheFolder, "key-bindings-pwsh.ps1"));
|
|
233
|
-
break;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
};
|
package/build/utils/cache.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|
package/shell/key-bindings.bash
DELETED
package/shell/key-bindings.fish
DELETED
package/shell/key-bindings.zsh
DELETED