feat: add keybinding support for fish

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2023-10-26 22:47:42 -07:00
parent 07ffb6793a
commit 27686c9e9e
2 changed files with 32 additions and 1 deletions
+8
View File
@@ -0,0 +1,8 @@
function inshellisense-widget -d "Activate autocomplete"
inshellisense -c (commandline -b) -s fish
commandline -r ''
commandline -f repaint
# TODO: add support for history insertion
end
bind \ca inshellisense-widget
+24 -1
View File
@@ -17,9 +17,10 @@ export enum Shell {
Powershell = "powershell",
Pwsh = "pwsh",
Zsh = "zsh",
Fish = "fish",
}
export const supportedShells = [Shell.Bash, Shell.Powershell, Shell.Pwsh, Shell.Zsh];
export const supportedShells = [Shell.Bash, Shell.Powershell, Shell.Pwsh, Shell.Zsh, Shell.Fish];
const bashScriptCommand = (): string => {
return `[ -f ~/${cacheFolder}/key-bindings.bash ] && source ~/${cacheFolder}/key-bindings.bash`;
@@ -29,6 +30,10 @@ const zshScriptCommand = (): string => {
return `[ -f ~/${cacheFolder}/key-bindings.zsh ] && source ~/${cacheFolder}/key-bindings.zsh`;
};
const fishScriptCommand = (): string => {
return `[ -f ~/${cacheFolder}/key-bindings.fish ] && source ~/${cacheFolder}/key-bindings.fish`;
};
const powershellScriptCommand = (): string => {
const bindingsPath = path.join(os.homedir(), cacheFolder, "key-bindings-powershell.ps1");
return `if(Test-Path '${bindingsPath}' -PathType Leaf){. ${bindingsPath}}`;
@@ -78,6 +83,16 @@ export const availableBindings = async (): Promise<Shell[]> => {
}
}
const fishConfigPath = path.join(os.homedir(), ".config", "fish", "config.fish");
if (!fs.existsSync(fishConfigPath)) {
bindings.push(Shell.Fish);
} else {
const fishConfigContent = fsAsync.readFile(fishConfigPath, { encoding: "utf-8" });
if (!(await fishConfigContent).includes(fishScriptCommand())) {
bindings.push(Shell.Fish);
}
}
const powershellConfigPath = path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1");
if (!fs.existsSync(powershellConfigPath)) {
bindings.push(Shell.Powershell);
@@ -118,6 +133,14 @@ export const bind = async (shell: Shell): Promise<void> => {
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.zsh"), path.join(os.homedir(), cacheFolder, "key-bindings.zsh"));
break;
}
case Shell.Fish: {
const fishConfigDirectory = path.join(os.homedir(), ".config", "fish");
const fishConfigPath = path.join(fishConfigDirectory, "config.fish");
await fsAsync.mkdir(fishConfigDirectory, { recursive: true });
await fsAsync.appendFile(fishConfigPath, `\n${fishScriptCommand()}`);
await fsAsync.copyFile(path.join(__dirname, "..", "..", "shell", "key-bindings.fish"), path.join(os.homedir(), cacheFolder, "key-bindings.fish"));
break;
}
case Shell.Powershell: {
const powershellConfigPath = path.join(os.homedir(), "Documents", "WindowsPowershell", "Microsoft.PowerShell_profile.ps1");
await fsAsync.appendFile(powershellConfigPath, `\n${powershellScriptCommand()}`);