Add tab completion using argcomplete, update README
This commit is contained in:
10
README.md
10
README.md
@@ -113,6 +113,16 @@ Normal users: `~/.local/share/resrm/files`
|
|||||||
|
|
||||||
Root user: `/root/.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
|
## 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).
|
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
16
poetry.lock
generated
@@ -1,5 +1,19 @@
|
|||||||
# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand.
|
# 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]]
|
[[package]]
|
||||||
name = "cfgv"
|
name = "cfgv"
|
||||||
version = "3.4.0"
|
version = "3.4.0"
|
||||||
@@ -209,4 +223,4 @@ test = ["covdefaults (>=2.3)", "coverage (>=7.2.7)", "coverage-enable-subprocess
|
|||||||
[metadata]
|
[metadata]
|
||||||
lock-version = "2.0"
|
lock-version = "2.0"
|
||||||
python-versions = ">=3.10,<4.0"
|
python-versions = ">=3.10,<4.0"
|
||||||
content-hash = "140de3164bab6e634d9bd113a3ef763c3d9743a4065ff4fc6b57c17881faa858"
|
content-hash = "7f8ea4efe2d270a676fdd9c882c02f43b4b118bfe7a5fd6da1098ff4ec84ce3d"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "resrm"
|
name = "resrm"
|
||||||
version = "0.3.1"
|
version = "0.3.2"
|
||||||
description = "drop-in replacement for rm with undo/restore built-in."
|
description = "drop-in replacement for rm with undo/restore built-in."
|
||||||
authors = ["Marco D'Aleo <marco@marcodaleo.com>"]
|
authors = ["Marco D'Aleo <marco@marcodaleo.com>"]
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
@@ -11,6 +11,7 @@ packages = [{include = "resrm", from = "src"}]
|
|||||||
|
|
||||||
[tool.poetry.dependencies]
|
[tool.poetry.dependencies]
|
||||||
python = ">=3.10,<4.0"
|
python = ">=3.10,<4.0"
|
||||||
|
argcomplete = ">=2"
|
||||||
|
|
||||||
[tool.poetry.dev-dependencies]
|
[tool.poetry.dev-dependencies]
|
||||||
pre-commit = "^3.8"
|
pre-commit = "^3.8"
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ Basic usage:
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
import argparse
|
import argparse
|
||||||
|
import argcomplete
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@@ -385,13 +386,27 @@ def main(argv: Optional[List[str]] = None):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--skip-trash", action="store_true", help="permanent delete"
|
"--skip-trash", action="store_true", help="permanent delete"
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
restore_arg = parser.add_argument(
|
||||||
"--restore",
|
"--restore",
|
||||||
nargs="+",
|
nargs="+",
|
||||||
metavar="item",
|
metavar="item",
|
||||||
help="restore by id or basename",
|
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(
|
parser.add_argument(
|
||||||
"--empty", action="store_true", help="empty the trash permanently"
|
"--empty", action="store_true", help="empty the trash permanently"
|
||||||
)
|
)
|
||||||
@@ -399,6 +414,9 @@ def main(argv: Optional[List[str]] = None):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"-V", "--version", action="version", version=f"resrm {get_version()}"
|
"-V", "--version", action="version", version=f"resrm {get_version()}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
argcomplete.autocomplete(parser)
|
||||||
|
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
# Always print docstring if -h or --help
|
# Always print docstring if -h or --help
|
||||||
|
|||||||
Reference in New Issue
Block a user