From 9edae1d2331399c5d515573862bf78360c99c9fc Mon Sep 17 00:00:00 2001 From: Marco D'Aleo Date: Tue, 2 Dec 2025 18:01:17 +0000 Subject: [PATCH] Add tab completion using argcomplete, update README --- README.md | 10 ++++++++++ poetry.lock | 16 +++++++++++++++- pyproject.toml | 3 ++- src/resrm/core.py | 22 ++++++++++++++++++++-- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 6c37903..21ce8ca 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,16 @@ Normal users: `~/.local/share/resrm/files` Root user: `/root/.local/share/resrm/files` +### TAB completion +Add this to your `.bashrc` +``` +eval "$(register-python-argcomplete resrm)" +``` +And then +``` +source ~/.bashrc +``` + ## pre-commit This project uses [**pre-commit**](https://pre-commit.com/) to run automatic formatting and security checks before each commit (Black, Bandit, and various safety checks). diff --git a/poetry.lock b/poetry.lock index 140f80d..7bad964 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,5 +1,19 @@ # This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. +[[package]] +name = "argcomplete" +version = "3.6.3" +description = "Bash tab completion for argparse" +optional = false +python-versions = ">=3.8" +files = [ + {file = "argcomplete-3.6.3-py3-none-any.whl", hash = "sha256:f5007b3a600ccac5d25bbce33089211dfd49eab4a7718da3f10e3082525a92ce"}, + {file = "argcomplete-3.6.3.tar.gz", hash = "sha256:62e8ed4fd6a45864acc8235409461b72c9a28ee785a2011cc5eb78318786c89c"}, +] + +[package.extras] +test = ["coverage", "mypy", "pexpect", "ruff", "wheel"] + [[package]] name = "cfgv" version = "3.4.0" @@ -209,4 +223,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess [metadata] lock-version = "2.0" python-versions = ">=3.10,<4.0" -content-hash = "140de3164bab6e634d9bd113a3ef763c3d9743a4065ff4fc6b57c17881faa858" +content-hash = "7f8ea4efe2d270a676fdd9c882c02f43b4b118bfe7a5fd6da1098ff4ec84ce3d" diff --git a/pyproject.toml b/pyproject.toml index 53e6e4b..2cbee6f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "resrm" -version = "0.3.1" +version = "0.3.2" description = "drop-in replacement for rm with undo/restore built-in." authors = ["Marco D'Aleo "] license = "GPL-3.0-or-later" @@ -11,6 +11,7 @@ packages = [{include = "resrm", from = "src"}] [tool.poetry.dependencies] python = ">=3.10,<4.0" +argcomplete = ">=2" [tool.poetry.dev-dependencies] pre-commit = "^3.8" diff --git a/src/resrm/core.py b/src/resrm/core.py index 8f789c4..a46bc29 100644 --- a/src/resrm/core.py +++ b/src/resrm/core.py @@ -15,6 +15,7 @@ Basic usage: from __future__ import annotations import argparse +import argcomplete import json import os import shutil @@ -385,13 +386,27 @@ def main(argv: Optional[List[str]] = None): parser.add_argument( "--skip-trash", action="store_true", help="permanent delete" ) - parser.add_argument( + restore_arg = parser.add_argument( "--restore", nargs="+", metavar="item", help="restore by id or basename", ) - parser.add_argument("-l", action="store_true", help="list trash") + + # restore completer + def restore_completer(prefix, parsed_args, **kwargs): + return [ + short_id(m["id"]) + for m in meta + if short_id(m["id"]).startswith(prefix) + ] + [ + Path(m["orig_path"]).name + for m in meta + if Path(m["orig_path"]).name.startswith(prefix) + ] + + restore_arg.completer = restore_completer + parser.add_argument("-l", "--list", action="store_true", help="list trash") parser.add_argument( "--empty", action="store_true", help="empty the trash permanently" ) @@ -399,6 +414,9 @@ def main(argv: Optional[List[str]] = None): parser.add_argument( "-V", "--version", action="version", version=f"resrm {get_version()}" ) + + argcomplete.autocomplete(parser) + args = parser.parse_args(argv) # Always print docstring if -h or --help