diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish new file mode 100644 index 0000000..7afa9d3 --- /dev/null +++ b/shell/key-bindings.fish @@ -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 \ No newline at end of file diff --git a/src/utils/bindings.ts b/src/utils/bindings.ts index 91d8301..33f1ee4 100644 --- a/src/utils/bindings.ts +++ b/src/utils/bindings.ts @@ -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 => { } } + 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 => { 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()}`);