feat: trash files by default
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user