diff --git a/aider/args.py b/aider/args.py index 5b3fdf07faf..88a6b6bff81 100644 --- a/aider/args.py +++ b/aider/args.py @@ -849,6 +849,10 @@ def get_parser(default_config_files, git_root): "--editor", help="Specify which editor to use for the /editor command", ) + group.add_argument( + "--fzf-history-search", + help="Use fuzzy find (fzf) for backwards history search", + ) supported_shells_list = sorted(list(shtab.SUPPORTED_SHELLS)) group.add_argument( diff --git a/aider/io.py b/aider/io.py index ed6f22d51ae..9350aad481f 100644 --- a/aider/io.py +++ b/aider/io.py @@ -263,6 +263,7 @@ def __init__( root=".", notifications=False, notifications_command=None, + fzf_history_search=False, ): self.placeholder = None self.interrupted = False @@ -371,6 +372,8 @@ def __init__( # Validate color settings after console is initialized self._validate_color_settings() + self.fzf_history_search = fzf_history_search + def _validate_color_settings(self): """Validate configured color strings and reset invalid ones.""" color_attributes = [ @@ -594,6 +597,43 @@ def _(event): "Navigate forward through history" event.current_buffer.history_forward() + if self.fzf_history_search: + @kb.add("c-r") + def _(event): + if not self.input_history_file: + self.tool_error("Reverse search attempt without history file") + + event.app.reset() + + return + + history_lines = "\n".join( + FileHistory(self.input_history_file).load_history_strings() + ) + + fzf_result = ( + subprocess.run( + ["fzf", "--reverse", "--height", "20"], + check=False, + capture_output=True, + text=True, + input=history_lines, + ) + ) + if fzf_result.returncode != 0: + self.tool_error(f"fzf returned error: {fzf_result.stderr}") + + event.app.reset() + + return + + fzf_output = fzf_result.stdout.rstrip("\n") + + event.app.reset() + buffer = event.current_buffer + buffer.text = fzf_output + buffer.cursor_position = len(buffer.text) + @kb.add("c-x", "c-e") def _(event): "Edit current input in external editor (like Bash)" diff --git a/aider/main.py b/aider/main.py index afb3f836624..ede6ae32bf9 100644 --- a/aider/main.py +++ b/aider/main.py @@ -575,6 +575,7 @@ def get_io(pretty): multiline_mode=args.multiline, notifications=args.notifications, notifications_command=args.notifications_command, + fzf_history_search=args.fzf_history_search, ) io = get_io(args.pretty)