@microsoft/inshellisense 0.0.1-rc.21 → 0.0.1-rc.23
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/package.json +11 -78
- package/CODE_OF_CONDUCT.md +0 -9
- package/LICENSE +0 -21
- package/README.md +0 -132
- package/SECURITY.md +0 -41
- package/SUPPORT.md +0 -13
- package/build/commands/complete.js +0 -16
- package/build/commands/doctor.js +0 -11
- package/build/commands/init.js +0 -24
- package/build/commands/root.js +0 -37
- package/build/commands/specs/list.js +0 -26
- package/build/commands/specs/root.js +0 -8
- package/build/commands/uninstall.js +0 -11
- package/build/index.js +0 -35
- package/build/isterm/commandManager.js +0 -184
- package/build/isterm/index.js +0 -4
- package/build/isterm/pty.js +0 -361
- package/build/runtime/alias.js +0 -66
- package/build/runtime/generator.js +0 -55
- package/build/runtime/model.js +0 -3
- package/build/runtime/parser.js +0 -133
- package/build/runtime/runtime.js +0 -282
- package/build/runtime/spec.js +0 -36
- package/build/runtime/suggestion.js +0 -232
- package/build/runtime/template.js +0 -50
- package/build/runtime/utils.js +0 -121
- package/build/ui/suggestionManager.js +0 -162
- package/build/ui/ui-doctor.js +0 -69
- package/build/ui/ui-root.js +0 -141
- package/build/ui/ui-uninstall.js +0 -9
- package/build/ui/utils.js +0 -57
- package/build/utils/ansi.js +0 -37
- package/build/utils/config.js +0 -99
- package/build/utils/log.js +0 -39
- package/build/utils/shell.js +0 -318
- package/build/utils/version.js +0 -13
- package/scripts/postinstall.js +0 -9
- package/shell/bash-preexec.sh +0 -380
- package/shell/shellIntegration-env.zsh +0 -12
- package/shell/shellIntegration-login.zsh +0 -9
- package/shell/shellIntegration-profile.zsh +0 -9
- package/shell/shellIntegration-rc.zsh +0 -66
- package/shell/shellIntegration.bash +0 -114
- package/shell/shellIntegration.fish +0 -27
- package/shell/shellIntegration.nu +0 -29
- package/shell/shellIntegration.ps1 +0 -26
- package/shell/shellIntegration.xsh +0 -31
- package/todo.md +0 -17
package/build/utils/config.js
DELETED
|
@@ -1,99 +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 fs from "node:fs";
|
|
6
|
-
import fsAsync from "node:fs/promises";
|
|
7
|
-
import toml from "toml";
|
|
8
|
-
import _Ajv from "ajv";
|
|
9
|
-
const Ajv = _Ajv;
|
|
10
|
-
const ajv = new Ajv();
|
|
11
|
-
const bindingSchema = {
|
|
12
|
-
type: "object",
|
|
13
|
-
nullable: true,
|
|
14
|
-
properties: {
|
|
15
|
-
shift: { type: "boolean", nullable: true },
|
|
16
|
-
control: { type: "boolean", nullable: true },
|
|
17
|
-
key: { type: "string" },
|
|
18
|
-
},
|
|
19
|
-
required: ["key"],
|
|
20
|
-
};
|
|
21
|
-
const specPathsSchema = {
|
|
22
|
-
type: "array",
|
|
23
|
-
items: { type: "string" },
|
|
24
|
-
nullable: true,
|
|
25
|
-
};
|
|
26
|
-
const configSchema = {
|
|
27
|
-
type: "object",
|
|
28
|
-
nullable: true,
|
|
29
|
-
properties: {
|
|
30
|
-
bindings: {
|
|
31
|
-
type: "object",
|
|
32
|
-
nullable: true,
|
|
33
|
-
properties: {
|
|
34
|
-
nextSuggestion: bindingSchema,
|
|
35
|
-
previousSuggestion: bindingSchema,
|
|
36
|
-
dismissSuggestions: bindingSchema,
|
|
37
|
-
acceptSuggestion: bindingSchema,
|
|
38
|
-
},
|
|
39
|
-
},
|
|
40
|
-
specs: {
|
|
41
|
-
type: "object",
|
|
42
|
-
nullable: true,
|
|
43
|
-
properties: {
|
|
44
|
-
path: specPathsSchema,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
additionalProperties: false,
|
|
49
|
-
};
|
|
50
|
-
const rcFile = ".inshellisenserc";
|
|
51
|
-
const xdgFile = "rc.toml";
|
|
52
|
-
const cachePath = path.join(os.homedir(), ".inshellisense");
|
|
53
|
-
const rcPath = path.join(os.homedir(), rcFile);
|
|
54
|
-
const xdgPath = path.join(os.homedir(), ".config", "inshellisense", xdgFile);
|
|
55
|
-
const configPaths = [rcPath, xdgPath];
|
|
56
|
-
let globalConfig = {
|
|
57
|
-
bindings: {
|
|
58
|
-
nextSuggestion: { key: "down" },
|
|
59
|
-
previousSuggestion: { key: "up" },
|
|
60
|
-
acceptSuggestion: { key: "tab" },
|
|
61
|
-
dismissSuggestions: { key: "escape" },
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
export const getConfig = () => globalConfig;
|
|
65
|
-
export const loadConfig = async (program) => {
|
|
66
|
-
configPaths.forEach(async (configPath) => {
|
|
67
|
-
if (fs.existsSync(configPath)) {
|
|
68
|
-
let config;
|
|
69
|
-
try {
|
|
70
|
-
config = toml.parse((await fsAsync.readFile(configPath)).toString());
|
|
71
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
72
|
-
}
|
|
73
|
-
catch (e) {
|
|
74
|
-
program.error(`${configPath} is invalid toml. Parsing error on line ${e.line}, column ${e.column}: ${e.message}`);
|
|
75
|
-
}
|
|
76
|
-
const isValid = ajv.validate(configSchema, config);
|
|
77
|
-
if (!isValid) {
|
|
78
|
-
program.error(`${configPath} is invalid: ${ajv.errorsText()}`);
|
|
79
|
-
}
|
|
80
|
-
globalConfig = {
|
|
81
|
-
bindings: {
|
|
82
|
-
nextSuggestion: config?.bindings?.nextSuggestion ?? globalConfig.bindings.nextSuggestion,
|
|
83
|
-
previousSuggestion: config?.bindings?.previousSuggestion ?? globalConfig.bindings.previousSuggestion,
|
|
84
|
-
acceptSuggestion: config?.bindings?.acceptSuggestion ?? globalConfig.bindings.acceptSuggestion,
|
|
85
|
-
dismissSuggestions: config?.bindings?.dismissSuggestions ?? globalConfig.bindings.dismissSuggestions,
|
|
86
|
-
},
|
|
87
|
-
specs: {
|
|
88
|
-
path: [...(config?.specs?.path ?? []), ...(config?.specs?.path ?? [])],
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
globalConfig.specs = { path: [`${os.homedir()}/.fig/autocomplete/build`, ...(globalConfig.specs?.path ?? [])] };
|
|
94
|
-
};
|
|
95
|
-
export const deleteCacheFolder = () => {
|
|
96
|
-
if (fs.existsSync(cachePath)) {
|
|
97
|
-
fs.rmSync(cachePath, { recursive: true });
|
|
98
|
-
}
|
|
99
|
-
};
|
package/build/utils/log.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4
|
-
import os from "node:os";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import fs from "node:fs";
|
|
7
|
-
import fsAsync from "node:fs/promises";
|
|
8
|
-
const logFolder = path.join(os.homedir(), ".inshellisense");
|
|
9
|
-
const logTarget = path.join(logFolder, "inshellisense.log");
|
|
10
|
-
let logEnabled = false;
|
|
11
|
-
const reset = async () => {
|
|
12
|
-
if (!fs.existsSync(logTarget)) {
|
|
13
|
-
await fsAsync.mkdir(logFolder, { recursive: true });
|
|
14
|
-
}
|
|
15
|
-
await fsAsync.writeFile(logTarget, "");
|
|
16
|
-
};
|
|
17
|
-
const debug = (content) => {
|
|
18
|
-
if (!logEnabled) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
fs.appendFile(logTarget, JSON.stringify(content) + "\n", (err) => {
|
|
22
|
-
if (err != null) {
|
|
23
|
-
throw err;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
const getLogFunction = (level) => (...data) => debug({ msg: `console.${level}`, data: data.toString() });
|
|
28
|
-
const logConsole = {
|
|
29
|
-
...console,
|
|
30
|
-
log: getLogFunction("log"),
|
|
31
|
-
error: getLogFunction("error"),
|
|
32
|
-
};
|
|
33
|
-
// eslint-disable-next-line no-global-assign
|
|
34
|
-
const overrideConsole = () => (console = logConsole);
|
|
35
|
-
export const enable = async () => {
|
|
36
|
-
await reset();
|
|
37
|
-
logEnabled = true;
|
|
38
|
-
};
|
|
39
|
-
export default { reset, debug, enable, overrideConsole };
|
package/build/utils/shell.js
DELETED
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
import process from "node:process";
|
|
4
|
-
import find from "find-process";
|
|
5
|
-
import path from "node:path";
|
|
6
|
-
import which from "which";
|
|
7
|
-
import fs from "node:fs";
|
|
8
|
-
import url from "node:url";
|
|
9
|
-
import os from "node:os";
|
|
10
|
-
import fsAsync from "node:fs/promises";
|
|
11
|
-
import util from "node:util";
|
|
12
|
-
import childProcess from "node:child_process";
|
|
13
|
-
import log from "./log.js";
|
|
14
|
-
const exec = util.promisify(childProcess.exec);
|
|
15
|
-
const safeExec = async (command, options) => {
|
|
16
|
-
const defaultOptions = { timeout: 500, env: { ISTERM: "1" } };
|
|
17
|
-
try {
|
|
18
|
-
const { stdout, stderr } = await exec(command, { ...defaultOptions, ...options });
|
|
19
|
-
return { stdout, stderr };
|
|
20
|
-
}
|
|
21
|
-
catch (e) {
|
|
22
|
-
log.debug({ msg: `error executing exec command: ${e}` });
|
|
23
|
-
return { stdout: undefined, stderr: undefined };
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
export var Shell;
|
|
27
|
-
(function (Shell) {
|
|
28
|
-
Shell["Bash"] = "bash";
|
|
29
|
-
Shell["Powershell"] = "powershell";
|
|
30
|
-
Shell["Pwsh"] = "pwsh";
|
|
31
|
-
Shell["Zsh"] = "zsh";
|
|
32
|
-
Shell["Fish"] = "fish";
|
|
33
|
-
Shell["Cmd"] = "cmd";
|
|
34
|
-
Shell["Xonsh"] = "xonsh";
|
|
35
|
-
Shell["Nushell"] = "nu";
|
|
36
|
-
})(Shell || (Shell = {}));
|
|
37
|
-
export const supportedShells = [
|
|
38
|
-
Shell.Bash,
|
|
39
|
-
process.platform == "win32" ? Shell.Powershell : null,
|
|
40
|
-
Shell.Pwsh,
|
|
41
|
-
Shell.Zsh,
|
|
42
|
-
Shell.Fish,
|
|
43
|
-
process.platform == "win32" ? Shell.Cmd : null,
|
|
44
|
-
Shell.Xonsh,
|
|
45
|
-
Shell.Nushell,
|
|
46
|
-
].filter((shell) => shell != null);
|
|
47
|
-
export const initSupportedShells = supportedShells.filter((shell) => shell != Shell.Cmd);
|
|
48
|
-
export const aliasSupportedShells = [Shell.Bash, Shell.Zsh];
|
|
49
|
-
export const userZdotdir = process.env?.ZDOTDIR ?? os.homedir() ?? `~`;
|
|
50
|
-
export const zdotdir = path.join(os.tmpdir(), `is-zsh`);
|
|
51
|
-
const configFolder = ".inshellisense";
|
|
52
|
-
export const checkShellConfigs = () => {
|
|
53
|
-
const shellsWithoutConfigs = [];
|
|
54
|
-
const configFolderPath = path.join(os.homedir(), configFolder);
|
|
55
|
-
for (const shell of supportedShells) {
|
|
56
|
-
const shellConfigName = getShellConfigName(shell);
|
|
57
|
-
if (shellConfigName == null)
|
|
58
|
-
continue;
|
|
59
|
-
if (!fs.existsSync(path.join(configFolderPath, shell, shellConfigName))) {
|
|
60
|
-
shellsWithoutConfigs.push(shell);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return shellsWithoutConfigs;
|
|
64
|
-
};
|
|
65
|
-
export const checkLegacyConfigs = async () => {
|
|
66
|
-
const shellsWithLegacyConfig = [];
|
|
67
|
-
for (const shell of supportedShells) {
|
|
68
|
-
const profilePath = await getProfilePath(shell);
|
|
69
|
-
if (profilePath != null && fs.existsSync(profilePath)) {
|
|
70
|
-
const profile = await fsAsync.readFile(profilePath, "utf8");
|
|
71
|
-
if (profile.includes("inshellisense shell plugin")) {
|
|
72
|
-
shellsWithLegacyConfig.push(shell);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return shellsWithLegacyConfig;
|
|
77
|
-
};
|
|
78
|
-
export const checkShellConfigPlugin = async () => {
|
|
79
|
-
const shellsWithoutPlugin = [];
|
|
80
|
-
const shellsWithBadPlugin = [];
|
|
81
|
-
for (const shell of supportedShells) {
|
|
82
|
-
const profilePath = await getProfilePath(shell);
|
|
83
|
-
if (profilePath != null && fs.existsSync(profilePath)) {
|
|
84
|
-
const profile = await fsAsync.readFile(profilePath, "utf8");
|
|
85
|
-
const shellSourceCommand = getShellSourceCommand(shell).trim();
|
|
86
|
-
const profileContainsSource = profile.includes(shellSourceCommand);
|
|
87
|
-
const profileEndsWithSource = profile.trimEnd().endsWith(shellSourceCommand);
|
|
88
|
-
if (!profileContainsSource) {
|
|
89
|
-
shellsWithoutPlugin.push(shell);
|
|
90
|
-
}
|
|
91
|
-
else if (!profileEndsWithSource) {
|
|
92
|
-
shellsWithBadPlugin.push(shell);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return { shellsWithoutPlugin, shellsWithBadPlugin };
|
|
97
|
-
};
|
|
98
|
-
const getProfilePath = async (shell) => {
|
|
99
|
-
switch (shell) {
|
|
100
|
-
case Shell.Bash:
|
|
101
|
-
return path.join(os.homedir(), ".bashrc");
|
|
102
|
-
case Shell.Powershell:
|
|
103
|
-
return (await safeExec(`echo $profile`, { shell })).stdout?.trim();
|
|
104
|
-
case Shell.Pwsh:
|
|
105
|
-
return (await safeExec(`echo $profile`, { shell })).stdout?.trim();
|
|
106
|
-
case Shell.Zsh:
|
|
107
|
-
return path.join(os.homedir(), ".zshrc");
|
|
108
|
-
case Shell.Fish:
|
|
109
|
-
return path.join(os.homedir(), ".config", "fish", "config.fish");
|
|
110
|
-
case Shell.Xonsh:
|
|
111
|
-
return path.join(os.homedir(), ".xonshrc");
|
|
112
|
-
case Shell.Nushell:
|
|
113
|
-
return (await safeExec(`echo $nu.env-path`, { shell })).stdout?.trim();
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
export const createShellConfigs = async () => {
|
|
117
|
-
const configFolderPath = path.join(os.homedir(), configFolder);
|
|
118
|
-
for (const shell of supportedShells) {
|
|
119
|
-
const shellConfigName = getShellConfigName(shell);
|
|
120
|
-
if (shellConfigName == null)
|
|
121
|
-
continue;
|
|
122
|
-
await fsAsync.mkdir(path.join(configFolderPath, shell), { recursive: true });
|
|
123
|
-
await fsAsync.writeFile(path.join(configFolderPath, shell, shellConfigName), getShellConfig(shell));
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
const getShellConfigName = (shell) => {
|
|
127
|
-
switch (shell) {
|
|
128
|
-
case Shell.Bash:
|
|
129
|
-
return "init.sh";
|
|
130
|
-
case Shell.Powershell:
|
|
131
|
-
case Shell.Pwsh:
|
|
132
|
-
return "init.ps1";
|
|
133
|
-
case Shell.Zsh:
|
|
134
|
-
return "init.zsh";
|
|
135
|
-
case Shell.Fish:
|
|
136
|
-
return "init.fish";
|
|
137
|
-
case Shell.Xonsh:
|
|
138
|
-
return "init.xsh";
|
|
139
|
-
case Shell.Nushell:
|
|
140
|
-
return "init.nu";
|
|
141
|
-
default:
|
|
142
|
-
return undefined;
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
export const setupBashPreExec = async () => {
|
|
146
|
-
const shellFolderPath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "..", "shell");
|
|
147
|
-
const globalConfigPath = path.join(os.homedir(), configFolder);
|
|
148
|
-
if (!fs.existsSync(globalConfigPath)) {
|
|
149
|
-
await fsAsync.mkdir(globalConfigPath, { recursive: true });
|
|
150
|
-
}
|
|
151
|
-
await fsAsync.cp(path.join(shellFolderPath, "bash-preexec.sh"), path.join(globalConfigPath, "bash-preexec.sh"));
|
|
152
|
-
};
|
|
153
|
-
export const setupZshDotfiles = async () => {
|
|
154
|
-
const shellFolderPath = path.join(path.dirname(url.fileURLToPath(import.meta.url)), "..", "..", "shell");
|
|
155
|
-
await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-rc.zsh"), path.join(zdotdir, ".zshrc"));
|
|
156
|
-
await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-profile.zsh"), path.join(zdotdir, ".zprofile"));
|
|
157
|
-
await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-env.zsh"), path.join(zdotdir, ".zshenv"));
|
|
158
|
-
await fsAsync.cp(path.join(shellFolderPath, "shellIntegration-login.zsh"), path.join(zdotdir, ".zlogin"));
|
|
159
|
-
};
|
|
160
|
-
const findParentProcess = async () => {
|
|
161
|
-
try {
|
|
162
|
-
return (await find("pid", process.ppid)).at(0);
|
|
163
|
-
}
|
|
164
|
-
catch (e) {
|
|
165
|
-
log.debug({ msg: `error finding parent process: ${e}` });
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
export const inferShell = async () => {
|
|
169
|
-
// try getting shell from shell specific env variables
|
|
170
|
-
if (process.env.NU_VERSION != null) {
|
|
171
|
-
return Shell.Nushell;
|
|
172
|
-
}
|
|
173
|
-
else if (process.env.XONSHRC != null) {
|
|
174
|
-
return Shell.Xonsh;
|
|
175
|
-
}
|
|
176
|
-
else if (process.env.FISH_VERSION != null) {
|
|
177
|
-
return Shell.Fish;
|
|
178
|
-
}
|
|
179
|
-
else if (process.env.ZSH_VERSION != null) {
|
|
180
|
-
return Shell.Zsh;
|
|
181
|
-
}
|
|
182
|
-
else if (process.env.BASH_VERSION != null) {
|
|
183
|
-
return Shell.Bash;
|
|
184
|
-
}
|
|
185
|
-
// try getting shell from env
|
|
186
|
-
try {
|
|
187
|
-
const name = path.parse(process.env.SHELL ?? "").name;
|
|
188
|
-
const shellName = supportedShells.find((shell) => name.includes(shell));
|
|
189
|
-
if (shellName)
|
|
190
|
-
return shellName;
|
|
191
|
-
}
|
|
192
|
-
catch {
|
|
193
|
-
/* empty */
|
|
194
|
-
}
|
|
195
|
-
// try getting shell from parent process
|
|
196
|
-
const processResult = await findParentProcess();
|
|
197
|
-
const name = processResult?.name;
|
|
198
|
-
return name != null ? supportedShells.find((shell) => name.includes(shell)) : undefined;
|
|
199
|
-
};
|
|
200
|
-
export const gitBashPath = async () => {
|
|
201
|
-
const gitBashPaths = await getGitBashPaths();
|
|
202
|
-
for (const gitBashPath of gitBashPaths) {
|
|
203
|
-
if (fs.existsSync(gitBashPath)) {
|
|
204
|
-
return gitBashPath;
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
throw new Error("unable to find a git bash executable installed");
|
|
208
|
-
};
|
|
209
|
-
const getGitBashPaths = async () => {
|
|
210
|
-
const gitDirs = new Set();
|
|
211
|
-
const gitExePath = await which("git.exe", { nothrow: true });
|
|
212
|
-
if (gitExePath) {
|
|
213
|
-
const gitExeDir = path.dirname(gitExePath);
|
|
214
|
-
gitDirs.add(path.resolve(gitExeDir, "../.."));
|
|
215
|
-
}
|
|
216
|
-
const addValid = (set, value) => {
|
|
217
|
-
if (value)
|
|
218
|
-
set.add(value);
|
|
219
|
-
};
|
|
220
|
-
// Add common git install locations
|
|
221
|
-
addValid(gitDirs, process.env["ProgramW6432"]);
|
|
222
|
-
addValid(gitDirs, process.env["ProgramFiles"]);
|
|
223
|
-
addValid(gitDirs, process.env["ProgramFiles(X86)"]);
|
|
224
|
-
addValid(gitDirs, `${process.env["LocalAppData"]}\\Program`);
|
|
225
|
-
const gitBashPaths = [];
|
|
226
|
-
for (const gitDir of gitDirs) {
|
|
227
|
-
gitBashPaths.push(`${gitDir}\\Git\\bin\\bash.exe`, `${gitDir}\\Git\\usr\\bin\\bash.exe`, `${gitDir}\\usr\\bin\\bash.exe`);
|
|
228
|
-
}
|
|
229
|
-
// Add special installs that don't follow the standard directory structure
|
|
230
|
-
gitBashPaths.push(`${process.env["UserProfile"]}\\scoop\\apps\\git\\current\\bin\\bash.exe`);
|
|
231
|
-
gitBashPaths.push(`${process.env["UserProfile"]}\\scoop\\apps\\git-with-openssh\\current\\bin\\bash.exe`);
|
|
232
|
-
return gitBashPaths;
|
|
233
|
-
};
|
|
234
|
-
export const getBackspaceSequence = (press, shell) => shell === Shell.Pwsh || shell === Shell.Powershell || shell === Shell.Cmd || shell === Shell.Nushell ? "\u007F" : press[1].sequence;
|
|
235
|
-
export const getPathSeparator = (shell) => (shell == Shell.Bash || shell == Shell.Xonsh || shell == Shell.Nushell ? "/" : path.sep);
|
|
236
|
-
export const removePathSeparator = (dir) => {
|
|
237
|
-
return dir.endsWith("/") || dir.endsWith("\\") ? dir.slice(0, -1) : dir;
|
|
238
|
-
};
|
|
239
|
-
export const addPathSeparator = (dir, shell) => {
|
|
240
|
-
const pathSep = getPathSeparator(shell);
|
|
241
|
-
return dir.endsWith(pathSep) ? dir : dir + pathSep;
|
|
242
|
-
};
|
|
243
|
-
export const getPathDirname = (dir, shell) => {
|
|
244
|
-
const pathSep = getPathSeparator(shell);
|
|
245
|
-
return dir.endsWith(pathSep) || path.dirname(dir) == "." ? dir : addPathSeparator(path.dirname(dir), shell);
|
|
246
|
-
};
|
|
247
|
-
// nu fully re-writes the prompt every keystroke resulting in duplicate start/end sequences on the same line & re-writes the prompt after accepting a command
|
|
248
|
-
// xonsh re-writes the prompt after accepting a command
|
|
249
|
-
export const getShellPromptRewrites = (shell) => shell == Shell.Nushell || shell == Shell.Xonsh;
|
|
250
|
-
export const getShellSourceCommand = (shell) => {
|
|
251
|
-
switch (shell) {
|
|
252
|
-
case Shell.Bash:
|
|
253
|
-
return `[ -f ~/.inshellisense/bash/init.sh ] && source ~/.inshellisense/bash/init.sh`;
|
|
254
|
-
case Shell.Powershell:
|
|
255
|
-
return `if ( Test-Path '~/.inshellisense/powershell/init.ps1' -PathType Leaf ) { . ~/.inshellisense/powershell/init.ps1 }`;
|
|
256
|
-
case Shell.Pwsh:
|
|
257
|
-
return `if ( Test-Path '~/.inshellisense/pwsh/init.ps1' -PathType Leaf ) { . ~/.inshellisense/pwsh/init.ps1 }`;
|
|
258
|
-
case Shell.Zsh:
|
|
259
|
-
return `[[ -f ~/.inshellisense/zsh/init.zsh ]] && source ~/.inshellisense/zsh/init.zsh`;
|
|
260
|
-
case Shell.Fish:
|
|
261
|
-
return `test -f ~/.inshellisense/fish/init.fish && source ~/.inshellisense/fish/init.fish`;
|
|
262
|
-
case Shell.Xonsh:
|
|
263
|
-
return `p"~/.inshellisense/xonsh/init.xsh".exists() && source "~/.inshellisense/xonsh/init.xsh"`;
|
|
264
|
-
case Shell.Nushell:
|
|
265
|
-
return `if ( '~/.inshellisense/nu/init.nu' | path exists ) { source ~/.inshellisense/nu/init.nu }`;
|
|
266
|
-
}
|
|
267
|
-
return "";
|
|
268
|
-
};
|
|
269
|
-
export const getShellConfig = (shell) => {
|
|
270
|
-
switch (shell) {
|
|
271
|
-
case Shell.Zsh:
|
|
272
|
-
return `if [[ -z "\${ISTERM}" && $- = *i* && $- != *c* && -z "\${VSCODE_RESOLVING_ENVIRONMENT}" ]]; then
|
|
273
|
-
if [[ -o login ]]; then
|
|
274
|
-
is -s zsh --login ; exit
|
|
275
|
-
else
|
|
276
|
-
is -s zsh ; exit
|
|
277
|
-
fi
|
|
278
|
-
fi`;
|
|
279
|
-
case Shell.Bash:
|
|
280
|
-
return `if [[ -z "\${ISTERM}" && $- = *i* && $- != *c* && -z "\${VSCODE_RESOLVING_ENVIRONMENT}" ]]; then
|
|
281
|
-
shopt -q login_shell
|
|
282
|
-
login_shell=$?
|
|
283
|
-
if [ $login_shell -eq 0 ]; then
|
|
284
|
-
is -s bash --login ; exit
|
|
285
|
-
else
|
|
286
|
-
is -s bash ; exit
|
|
287
|
-
fi
|
|
288
|
-
fi`;
|
|
289
|
-
case Shell.Powershell:
|
|
290
|
-
case Shell.Pwsh:
|
|
291
|
-
return `$__IsCommandFlag = ([Environment]::GetCommandLineArgs() | ForEach-Object { $_.contains("-Command") }) -contains $true
|
|
292
|
-
$__IsNoExitFlag = ([Environment]::GetCommandLineArgs() | ForEach-Object { $_.contains("-NoExit") }) -contains $true
|
|
293
|
-
$__IsInteractive = -not $__IsCommandFlag -or ($__IsCommandFlag -and $__IsNoExitFlag)
|
|
294
|
-
if ([string]::IsNullOrEmpty($env:ISTERM) -and [Environment]::UserInteractive -and $__IsInteractive -and [string]::IsNullOrEmpty($env:VSCODE_RESOLVING_ENVIRONMENT)) {
|
|
295
|
-
is -s ${shell}
|
|
296
|
-
Stop-Process -Id $pid
|
|
297
|
-
}`;
|
|
298
|
-
case Shell.Fish:
|
|
299
|
-
return `if test -z "$ISTERM" && status --is-interactive && test -z "$VSCODE_RESOLVING_ENVIRONMENT"
|
|
300
|
-
if status --is-login
|
|
301
|
-
is -s fish --login ; kill %self
|
|
302
|
-
else
|
|
303
|
-
is -s fish ; kill %self
|
|
304
|
-
end
|
|
305
|
-
end`;
|
|
306
|
-
case Shell.Xonsh:
|
|
307
|
-
return `if 'ISTERM' not in \${...} and $XONSH_INTERACTIVE and 'VSCODE_RESOLVING_ENVIRONMENT' not in \${...}:
|
|
308
|
-
if $XONSH_LOGIN:
|
|
309
|
-
is -s xonsh --login ; exit
|
|
310
|
-
else:
|
|
311
|
-
is -s xonsh ; exit`;
|
|
312
|
-
case Shell.Nushell:
|
|
313
|
-
return `if "ISTERM" not-in $env and $nu.is-interactive and "VSCODE_RESOLVING_ENVIRONMENT" not-in $env {
|
|
314
|
-
if $nu.is-login { is -s nu --login ; exit } else { is -s nu ; exit }
|
|
315
|
-
}`;
|
|
316
|
-
}
|
|
317
|
-
return "";
|
|
318
|
-
};
|
package/build/utils/version.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
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/scripts/postinstall.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import fs from "node:fs";
|
|
5
|
-
|
|
6
|
-
if (fs.existsSync("./build/commands/init.js")) {
|
|
7
|
-
const init = (await import("../build/commands/init.js")).default;
|
|
8
|
-
init.parse(["--generate-full-configs"], { from: "user" });
|
|
9
|
-
}
|