feat: trash files by default
This commit is contained in:
@@ -6,6 +6,7 @@ readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = [
|
||||
"requests>=2.32.5",
|
||||
"send2trash>=2.1.0",
|
||||
"textual>=8.2.7",
|
||||
"typed-argparse>=0.3.1",
|
||||
]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -155,6 +155,7 @@ version = "0.1.0"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "requests" },
|
||||
{ name = "send2trash" },
|
||||
{ name = "textual" },
|
||||
{ name = "typed-argparse" },
|
||||
]
|
||||
@@ -162,6 +163,7 @@ dependencies = [
|
||||
[package.metadata]
|
||||
requires-dist = [
|
||||
{ name = "requests", specifier = ">=2.32.5" },
|
||||
{ name = "send2trash", specifier = ">=2.1.0" },
|
||||
{ name = "textual", specifier = ">=8.2.7" },
|
||||
{ name = "typed-argparse", specifier = ">=0.3.1" },
|
||||
]
|
||||
@@ -194,6 +196,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/14/25/b208c5683343959b670dc001595f2f3737e051da617f66c31f7c4fa93abc/rich-14.3.3-py3-none-any.whl", hash = "sha256:793431c1f8619afa7d3b52b2cdec859562b950ea0d4b6b505397612db8d5362d", size = 310458, upload-time = "2026-02-19T17:23:13.732Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "send2trash"
|
||||
version = "2.1.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c5/f0/184b4b5f8d00f2a92cf96eec8967a3d550b52cf94362dad1100df9e48d57/send2trash-2.1.0.tar.gz", hash = "sha256:1c72b39f09457db3c05ce1d19158c2cbef4c32b8bedd02c155e49282b7ea7459", size = 17255, upload-time = "2026-01-14T06:27:36.056Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/1c/78/504fdd027da3b84ff1aecd9f6957e65f35134534ccc6da8628eb71e76d3f/send2trash-2.1.0-py3-none-any.whl", hash = "sha256:0da2f112e6d6bb22de6aa6daa7e144831a4febf2a87261451c4ad849fe9a873c", size = 17610, upload-time = "2026-01-14T06:27:35.218Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "textual"
|
||||
version = "8.2.7"
|
||||
|
||||
Reference in New Issue
Block a user