mirror of
https://github.com/wavetermdev/inshellisense.git
synced 2026-08-05 13:43:30 -07:00
feat: implement zsh keybindings/support
Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
__inshellisense__() {
|
||||
input=$LBUFFER
|
||||
LBUFFER=
|
||||
inshellisense -c "$input" -s zsh < $TTY
|
||||
print -s $(inshellisense --history)
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
zle -N __inshellisense __inshellisense__
|
||||
bindkey '^A' __inshellisense
|
||||
@@ -4,8 +4,8 @@
|
||||
import { render } from "../ui/ui-root.js";
|
||||
import { executeShellCommandTTY } from "../runtime/utils.js";
|
||||
import { saveCommand, loadCommand } from "../utils/cache.js";
|
||||
import { supportedShells as shells } from "../utils/bindings.js";
|
||||
|
||||
const shells = ["bash", "powershell", "pwsh"];
|
||||
export const supportedShells = shells.join(", ");
|
||||
|
||||
type RootCommandOptions = {
|
||||
@@ -21,7 +21,7 @@ export const action = async (options: RootCommandOptions) => {
|
||||
}
|
||||
|
||||
const shell = options.shell ?? "";
|
||||
if (!shells.includes(shell)) {
|
||||
if (!shells.map((s) => s.valueOf()).includes(shell)) {
|
||||
console.error(`Unsupported shell: '${shell}', supported shells: ${supportedShells}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
+22
-1
@@ -16,14 +16,19 @@ export enum Shell {
|
||||
Bash = "bash",
|
||||
Powershell = "powershell",
|
||||
Pwsh = "pwsh",
|
||||
Zsh = "zsh",
|
||||
}
|
||||
|
||||
export const supportedShells = [Shell.Bash, Shell.Powershell, Shell.Pwsh];
|
||||
export const supportedShells = [Shell.Bash, Shell.Powershell, Shell.Pwsh, Shell.Zsh];
|
||||
|
||||
const bashScriptCommand = (): string => {
|
||||
return `[ -f ~/${cacheFolder}/key-bindings.bash ] && source ~/${cacheFolder}/key-bindings.bash`;
|
||||
};
|
||||
|
||||
const zshScriptCommand = (): string => {
|
||||
return `[ -f ~/${cacheFolder}/key-bindings.zsh ] && source ~/${cacheFolder}/key-bindings.zsh`;
|
||||
};
|
||||
|
||||
const powershellScriptCommand = (): string => {
|
||||
const bindingsPath = path.join(os.homedir(), cacheFolder, "key-bindings-powershell.ps1");
|
||||
return `if(Test-Path '${bindingsPath}' -PathType Leaf){. ${bindingsPath}}`;
|
||||
@@ -63,6 +68,16 @@ export const availableBindings = async (): Promise<Shell[]> => {
|
||||
}
|
||||
}
|
||||
|
||||
const zshConfigPath = path.join(os.homedir(), ".zshrc");
|
||||
if (!fs.existsSync(zshConfigPath)) {
|
||||
bindings.push(Shell.Zsh);
|
||||
} else {
|
||||
const zshConfigContent = fsAsync.readFile(zshConfigPath, { encoding: "utf-8" });
|
||||
if (!(await zshConfigContent).includes(zshScriptCommand())) {
|
||||
bindings.push(Shell.Zsh);
|
||||
}
|
||||
}
|
||||
|
||||
const powershellConfigPath = path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1");
|
||||
if (!fs.existsSync(powershellConfigPath)) {
|
||||
bindings.push(Shell.Powershell);
|
||||
@@ -97,6 +112,12 @@ export const bind = async (shell: Shell): Promise<void> => {
|
||||
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.bash"), path.join(os.homedir(), cacheFolder, "key-bindings.bash"));
|
||||
break;
|
||||
}
|
||||
case Shell.Zsh: {
|
||||
const zshConfigPath = path.join(os.homedir(), ".zshrc");
|
||||
await fsAsync.appendFile(zshConfigPath, `\n${zshScriptCommand()}`);
|
||||
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.zsh"), path.join(os.homedir(), cacheFolder, "key-bindings.zsh"));
|
||||
break;
|
||||
}
|
||||
case Shell.Powershell: {
|
||||
const powershellConfigPath = path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1");
|
||||
await fsAsync.appendFile(powershellConfigPath, `\n${powershellScriptCommand()}`);
|
||||
|
||||
Reference in New Issue
Block a user