diff --git a/README.md b/README.md index 045eb87..3b8ecfd 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Upgrading to the latest version of ShellOracle is just as simple! ## Usage -ShellOracle is designed to be used as a BASH/ZSH widget activated by the CTRL+F keyboard shortcut. +ShellOracle is designed to be used as a BASH/ZSH/fish widget activated by the CTRL+F keyboard shortcut. 1. Press CTRL+F 2. Describe your command @@ -122,7 +122,7 @@ behavior. ### Software -ShellOracle supports BASH and ZSH on macOS and Linux. +ShellOracle supports BASH, ZSH and fish on macOS and Linux. ### Hardware diff --git a/src/shelloracle/bootstrap.py b/src/shelloracle/bootstrap.py index f00a430..32a8d6e 100644 --- a/src/shelloracle/bootstrap.py +++ b/src/shelloracle/bootstrap.py @@ -3,6 +3,7 @@ import inspect import shutil from pathlib import Path +import os from typing import TYPE_CHECKING, Any import tomlkit @@ -38,7 +39,7 @@ def replace_home_with_tilde(path: Path) -> Path: return Path("~") / relative_path -supported_shells = ("zsh", "bash") +supported_shells = ("zsh", "bash", "fish") def get_installed_shells() -> list[str]: @@ -49,18 +50,24 @@ def get_bundled_script_path(shell: str) -> Path: shell_dir = Path(__file__).parent / "shell" if shell == "zsh": return shell_dir / "shelloracle.zsh" + if shell == "fish": + return shell_dir / "shelloracle.fish" return shell_dir / "shelloracle.bash" def get_script_path(shell: str) -> Path: if shell == "zsh": return Path.home() / ".shelloracle.zsh" + if shell == "fish": + return Path.home() / ".shelloracle.fish" return Path.home() / ".shelloracle.bash" def get_rc_path(shell: str) -> Path: if shell == "zsh": return Path.home() / ".zshrc" + if shell == "fish": + return Path.home() / ".config/fish/config.fish" return Path.home() / ".bashrc" @@ -75,10 +82,13 @@ def update_rc(shell: str) -> None: rc_path = get_rc_path(shell) rc_path.touch(exist_ok=True) with rc_path.open("r") as file: - zshrc = file.read() - shelloracle_script = get_script_path(shell) - line = f"[ -f {shelloracle_script} ] && source {shelloracle_script}" - if line not in zshrc: + rc_content = file.read() + if shell == "fish": + line = f"source {get_script_path(shell)}" + else: + shelloracle_script = get_script_path(shell) + line = f"[ -f {shelloracle_script} ] && source {shelloracle_script}" + if line not in rc_content: with rc_path.open("a") as file: file.write("\n") file.write(line) @@ -119,16 +129,14 @@ def install_keybindings() -> None: if not (shells := get_installed_shells()): print_warning( "Cannot install keybindings: no compatible shells found. " - f"Supported shells: {', '.join(supported_shells)}" + f"Supported shells: {' '.join(supported_shells)}" ) return if confirm("Enable terminal keybindings and update rc?", suffix=" ([y]/n) ") is False: return - for shell in shells: + for shell in get_installed_shells(): write_script_home(shell) update_rc(shell) - - def user_configure_settings(provider: type[Provider]) -> dict[str, Any]: settings = {} for name, setting in get_settings(provider): diff --git a/src/shelloracle/providers/__init__.py b/src/shelloracle/providers/__init__.py index 046abf6..7c3467a 100644 --- a/src/shelloracle/providers/__init__.py +++ b/src/shelloracle/providers/__init__.py @@ -9,9 +9,9 @@ from collections.abc import AsyncIterator system_prompt = ( - "Based on the following user description, generate a corresponding Bash command. Focus solely " + "Based on the following user description, generate a corresponding shell command. Focus solely " "on interpreting the requirements and translating them into a single, executable Bash command. " - "Ensure accuracy and relevance to the user's description. The output should be a valid Bash " + "Ensure accuracy and relevance to the user's description. The output should be a valid shell " "command that directly aligns with the user's intent, ready for execution in a command-line " "environment. Do not output anything except for the command. No code block, no English explanation, " "no newlines, and no start/end tags." diff --git a/src/shelloracle/shell/shelloracle.fish b/src/shelloracle/shell/shelloracle.fish new file mode 100644 index 0000000..46529dd --- /dev/null +++ b/src/shelloracle/shell/shelloracle.fish @@ -0,0 +1,9 @@ +function __shelloracle__ + set -l output (shor) + if test $status -ne 0 + return $status + end + commandline -r -- $output +end + +bind \cf __shelloracle__