Add tab completion using argcomplete, update README

This commit is contained in:
2025-12-02 18:01:17 +00:00
parent e36ac044d9
commit 9edae1d233
4 changed files with 47 additions and 4 deletions

View File

@@ -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).

16
poetry.lock generated
View File

@@ -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"

View File

@@ -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 <marco@marcodaleo.com>"]
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"

View File

@@ -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