From 920b20b17dccb631acbaa23fa6f8defb3f7eb7fd Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 8 May 2025 14:31:56 -0700 Subject: [PATCH] feat: add --shell-completions arg for shell completion scripts --- aider/args.py | 12 ++++++++++++ aider/main.py | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/aider/args.py b/aider/args.py index cd6e4363d..4e57f5c35 100644 --- a/aider/args.py +++ b/aider/args.py @@ -811,6 +811,18 @@ def get_parser(default_config_files, git_root): help="Specify which editor to use for the /editor command", ) + supported_shells_list = sorted(list(shtab.SUPPORTED_SHELLS)) + group.add_argument( + "--shell-completions", + metavar="SHELL", + choices=supported_shells_list, + help=( + "Print shell completion script for the specified SHELL and exit. Supported shells:" + f" {', '.join(supported_shells_list)}. Example: aider --shell-completions bash" + ), + ) + + ########## group = parser.add_argument_group("Deprecated model settings") # Add deprecated model shortcut arguments diff --git a/aider/main.py b/aider/main.py index a37f16129..82d00f474 100644 --- a/aider/main.py +++ b/aider/main.py @@ -15,6 +15,7 @@ except ImportError: import importlib_resources from dotenv import load_dotenv +import shtab from prompt_toolkit.enums import EditingMode from aider import __version__, models, urls, utils @@ -502,6 +503,13 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F # Parse again to include any arguments that might have been defined in .env args = parser.parse_args(argv) + if args.shell_completions: + # Ensure parser.prog is set for shtab, though it should be by default + parser.prog = "aider" + print(shtab.complete(parser, shell=args.shell_completions)) + sys.exit(0) + + if git is None: args.git = False