feat: trash files by default

This commit is contained in:
2026-07-15 15:01:37 +03:00
parent c449a2dffd
commit a5c317f083
4 changed files with 30 additions and 2 deletions
+9
View File
@@ -4,6 +4,7 @@ import os
import pathlib
import requests
import send2trash
WEBHOOK_URL = os.environ.get("RANDOM_FILE_PICKER_WEBHOOK_URL", None)
MOVE_FOLDER = os.environ.get("RANDOM_FILE_PICKER_MOVE_FOLDER", None)
@@ -111,3 +112,11 @@ def move_file_to_move_folder(file_path: pathlib.Path) -> None:
destination_path = move_dir_path / f"{name}_{counter}{ext}"
counter += 1
_ = file_path.rename(destination_path)
def trash_file(file_path: pathlib.Path) -> None:
"""
Put the specified file into the system trash using the send2trash library.
:param file_path: The path of the file to be trashed.
"""
send2trash.send2trash(file_path)
+9 -2
View File
@@ -16,7 +16,7 @@ from textual.app import App, ComposeResult
from textual.binding import BindingType
from textual.widgets import Footer, Header, Label
from random_file_picker.core import collect_files, move_file_to_move_folder, upload_file
from random_file_picker.core import collect_files, move_file_to_move_folder, trash_file, upload_file
from random_file_picker.openers import (
is_geeqie_available,
open_file_in_dolphin,
@@ -35,6 +35,7 @@ class Args(tap.TypedArgs):
directory: str = tap.arg("-d", default=".", help="Directory to search for files")
recursive: bool = tap.arg("-r", "--recursive", "--descend", default=False, help="Whether to recurse into subdirectories")
use_geeqie: bool = tap.arg("--use-geeqie", default=False, help="Whether to use Geeqie as the image viewer")
no_trash: bool = tap.arg("--no-trash", default=False, help="Delete files immediately without moving to trash")
blacklist: list[str] | None = tap.arg("--blacklist", nargs="*", help="List of glob patterns to blacklist files")
whitelist: list[str] | None = tap.arg("--whitelist", nargs="*", help="List of glob patterns to whitelist files")
@@ -59,6 +60,7 @@ class MenuApp(App[None]):
blacklist: list[str] | None = None,
whitelist: list[str] | None = None,
use_geeqie: bool = False,
use_trash: bool = True,
):
super().__init__()
self.directory: pathlib.Path = pathlib.Path(directory)
@@ -67,6 +69,7 @@ class MenuApp(App[None]):
self.blacklist_patterns: list[str] = blacklist or []
self.whitelist_patterns: list[str] = whitelist or []
self.use_geeqie: bool = use_geeqie
self.use_trash: bool = use_trash
self.usable_files: list[pathlib.Path] = []
self.current_index: int = 0
self.current_file: pathlib.Path | None = None
@@ -168,7 +171,10 @@ class MenuApp(App[None]):
return
try:
self.current_file.unlink()
if self.use_trash:
trash_file(self.current_file)
else:
self.current_file.unlink()
_ = self.usable_files.pop(self.current_index)
self.query_one("#status", Label).update("✅ Deleted file")
@@ -261,6 +267,7 @@ def main_with_tap(args: Args) -> None:
blacklist=args.blacklist or [],
whitelist=args.whitelist or [],
use_geeqie=args.use_geeqie,
use_trash=not args.no_trash,
)
app.run()