Compare commits
8 Commits
v0.2.0
...
flags_impr
| Author | SHA1 | Date | |
|---|---|---|---|
| e5f029738a | |||
| 1fbe499177 | |||
| 662166afb8 | |||
|
|
7197bfce0c | ||
|
|
7ee0e0a99e | ||
| dcd1165066 | |||
|
|
45ebe97a9a | ||
| dfcffb19e4 |
1
.github/CODEOWNERS
vendored
Normal file
1
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* @mdaleo404
|
||||||
13
README.md
13
README.md
@@ -18,7 +18,14 @@ It moves files to a per-user _trash_ instead of permanently deleting them, while
|
|||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
**NOTE:** To use `resrm` with `sudo`, the path to `resrm` must be in the `$PATH` seen by `root`.\
|
**NOTE:** To use `resrm` with `sudo`, the path to `resrm` must be in the `$PATH` seen by `root`.\
|
||||||
Either install `resrm` as `root` (_preferred_), use `sudo -E resrm`, or add the `$PATH` to `/etc/sudoers` using its `Defaults secure_path` parameter.
|
Either:
|
||||||
|
|
||||||
|
* install `resrm` as `root` (_preferred_), or
|
||||||
|
* add the path to `resrm` to the `secure_path` parameter in `/etc/sudoers`. For example, where `/home/user/.local/bin` is where `resrm` is:
|
||||||
|
|
||||||
|
``` bash
|
||||||
|
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/user/.local/bin"
|
||||||
|
```
|
||||||
|
|
||||||
Install via PyPI (_preferred_):
|
Install via PyPI (_preferred_):
|
||||||
|
|
||||||
@@ -30,7 +37,7 @@ Or clone the repo and install locally:
|
|||||||
|
|
||||||
```bash
|
```bash
|
||||||
git clone https://github.com/mdaleo404/resrm.git
|
git clone https://github.com/mdaleo404/resrm.git
|
||||||
cd resrm/resrm
|
cd resrm/
|
||||||
poetry install
|
poetry install
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -66,4 +73,4 @@ resrm --empty
|
|||||||
|
|
||||||
Normal users: `~/.local/share/resrm/files`
|
Normal users: `~/.local/share/resrm/files`
|
||||||
|
|
||||||
Root user: `/root/.local/share/resrm/files`
|
Root user: `/root/.local/share/resrm/files`
|
||||||
|
|||||||
0
resrm/poetry.lock → poetry.lock
generated
0
resrm/poetry.lock → poetry.lock
generated
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "resrm"
|
name = "resrm"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
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"
|
||||||
@@ -1,69 +0,0 @@
|
|||||||
# resrm
|
|
||||||
|
|
||||||
**resrm** is a safe, drop-in replacement for the Linux `rm` command with **undo/restore support**.
|
|
||||||
It moves files to a per-user _trash_ instead of permanently deleting them, while still allowing full `sudo` support for root-owned files.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
- Move files and directories to a **trash folder** instead of permanent deletion
|
|
||||||
- Restore deleted files by **short ID or exact basename**
|
|
||||||
- Empty trash safely
|
|
||||||
- Supports `-r`, `-f`, `-i`, `--perma` options
|
|
||||||
- Works with `sudo` for root-owned files
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
**NOTE:** To use `resrm` with `sudo`, the path to `resrm` must be in the `$PATH` seen by `root`.\
|
|
||||||
Either install `resrm` as `root` (_preferred_), use `sudo -E resrm`, or add the `$PATH` to `/etc/sudoers` using its `Defaults secure_path` parameter.
|
|
||||||
|
|
||||||
Install via PyPI (_preferred_):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
pip install resrm
|
|
||||||
```
|
|
||||||
|
|
||||||
Or clone the repo and install locally:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
git clone https://github.com/mdaleo404/resrm.git
|
|
||||||
cd resrm/resrm
|
|
||||||
poetry install
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# Move files to trash
|
|
||||||
resrm file1 file2
|
|
||||||
|
|
||||||
# Recursive remove of a directory
|
|
||||||
resrm -r mydir
|
|
||||||
|
|
||||||
# Force remove (ignore nonexistent)
|
|
||||||
resrm -f file
|
|
||||||
|
|
||||||
# Interactive remove
|
|
||||||
resrm -i file
|
|
||||||
|
|
||||||
# Permanent delete (bypass trash)
|
|
||||||
resrm --perma file
|
|
||||||
|
|
||||||
# List trash entries
|
|
||||||
resrm -l
|
|
||||||
|
|
||||||
# Restore a file by ID or basename
|
|
||||||
resrm --restore <id|name>
|
|
||||||
|
|
||||||
# Empty the trash permanently
|
|
||||||
resrm --empty
|
|
||||||
```
|
|
||||||
|
|
||||||
## Trash Location
|
|
||||||
|
|
||||||
Normal users: `~/.local/share/resrm/files`
|
|
||||||
|
|
||||||
Root user: `/root/.local/share/resrm/files`
|
|
||||||
@@ -7,7 +7,7 @@ Basic usage:
|
|||||||
resrm -r dir # recursive remove (moves dir to trash)
|
resrm -r dir # recursive remove (moves dir to trash)
|
||||||
resrm -f file # ignore nonexistent, no prompt
|
resrm -f file # ignore nonexistent, no prompt
|
||||||
resrm -i file # interactive prompt before removal
|
resrm -i file # interactive prompt before removal
|
||||||
resrm --perma file # permanent delete (bypass trash)
|
resrm --skip-trash file # permanent delete (bypass trash)
|
||||||
resrm -l # list trash entries (neat table)
|
resrm -l # list trash entries (neat table)
|
||||||
resrm --restore <id|name> # restore by short-id (8 chars) or exact basename
|
resrm --restore <id|name> # restore by short-id (8 chars) or exact basename
|
||||||
resrm --empty # empty trash entries (permanent)
|
resrm --empty # empty trash entries (permanent)
|
||||||
@@ -116,6 +116,8 @@ def find_candidates(identifier: str) -> List[Dict]:
|
|||||||
if id_matches:
|
if id_matches:
|
||||||
return id_matches
|
return id_matches
|
||||||
|
|
||||||
|
return []
|
||||||
|
|
||||||
def restore_many(identifiers: List[str]):
|
def restore_many(identifiers: List[str]):
|
||||||
"""Restore multiple files, prompting when needed."""
|
"""Restore multiple files, prompting when needed."""
|
||||||
for identifier in identifiers:
|
for identifier in identifiers:
|
||||||
@@ -216,7 +218,7 @@ def empty_trash():
|
|||||||
save_meta(meta)
|
save_meta(meta)
|
||||||
print(f"Trash emptied ({count} entries removed).")
|
print(f"Trash emptied ({count} entries removed).")
|
||||||
|
|
||||||
def move_to_trash(path: Path, interactive: bool, force: bool, recursive: bool, perma: bool):
|
def move_to_trash(path: Path, interactive: bool, force: bool, skip_trash: bool):
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
if force:
|
if force:
|
||||||
return
|
return
|
||||||
@@ -224,7 +226,7 @@ def move_to_trash(path: Path, interactive: bool, force: bool, recursive: bool, p
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Interactive prompt
|
# Interactive prompt
|
||||||
if interactive:
|
if interactive and not force:
|
||||||
try:
|
try:
|
||||||
yn = input(f"remove '{path}'? [y/N] ").strip().lower()
|
yn = input(f"remove '{path}'? [y/N] ").strip().lower()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
@@ -234,7 +236,7 @@ def move_to_trash(path: Path, interactive: bool, force: bool, recursive: bool, p
|
|||||||
return
|
return
|
||||||
|
|
||||||
# Permanent delete path
|
# Permanent delete path
|
||||||
if perma:
|
if skip_trash:
|
||||||
try:
|
try:
|
||||||
if path.is_dir() and not path.is_symlink():
|
if path.is_dir() and not path.is_symlink():
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
@@ -305,20 +307,30 @@ def main(argv: Optional[List[str]] = None):
|
|||||||
parser = argparse.ArgumentParser(add_help=False)
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
parser.add_argument("paths", nargs="*", help="files to remove")
|
parser.add_argument("paths", nargs="*", help="files to remove")
|
||||||
parser.add_argument("-r", action="store_true", help="recursive")
|
parser.add_argument("-r", action="store_true", help="recursive")
|
||||||
parser.add_argument("-f", action="store_true", help="force")
|
parser.add_argument("-f", "--force", action="store_true", help="force")
|
||||||
parser.add_argument("-i", action="store_true", help="interactive")
|
parser.add_argument("-i", action="store_true", help="interactive")
|
||||||
parser.add_argument("--perma", action="store_true", help="permanent delete")
|
parser.add_argument("--skip-trash", action="store_true", help="permanent delete")
|
||||||
parser.add_argument("--restore", nargs="+", help="restore by id or basename")
|
parser.add_argument("--restore", nargs="+", metavar="item", help="restore by id or basename")
|
||||||
parser.add_argument("-l", action="store_true", help="list trash")
|
parser.add_argument("-l", action="store_true", help="list trash")
|
||||||
parser.add_argument("--empty", action="store_true", help="empty the trash permanently")
|
parser.add_argument("--empty", action="store_true", help="empty the trash permanently")
|
||||||
parser.add_argument("--help", action="store_true", help="show help")
|
parser.add_argument("-h", "--help", action="store_true", help="show help")
|
||||||
|
parser.add_argument("-V", "--version", action="store_true", help="show version")
|
||||||
args = parser.parse_args(argv)
|
args = parser.parse_args(argv)
|
||||||
|
|
||||||
# Always print docstring if --help or no args
|
# Always print docstring if -h or --help
|
||||||
if args.help or not argv:
|
if args.help:
|
||||||
print(__doc__)
|
print(__doc__)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if args.version:
|
||||||
|
print("resrm 0.2.1")
|
||||||
|
return
|
||||||
|
|
||||||
|
if not args.paths and not (args.l or args.empty or args.restore):
|
||||||
|
print("resrm: missing operand")
|
||||||
|
print("Try 'resrm --help' for more information.")
|
||||||
|
return
|
||||||
|
|
||||||
if args.l:
|
if args.l:
|
||||||
list_trash()
|
list_trash()
|
||||||
return
|
return
|
||||||
@@ -344,4 +356,4 @@ def main(argv: Optional[List[str]] = None):
|
|||||||
continue
|
continue
|
||||||
print(f"resrm: cannot remove '{pth}': Is a directory")
|
print(f"resrm: cannot remove '{pth}': Is a directory")
|
||||||
continue
|
continue
|
||||||
move_to_trash(pth, interactive=args.i, force=args.f, recursive=args.r, perma=args.perma)
|
move_to_trash(pth, interactive=args.i, force=args.force, skip_trash=args.skip_trash)
|
||||||
Reference in New Issue
Block a user