From cc52947d577f266ae60f7a5a1bf21c6a9473ac7d Mon Sep 17 00:00:00 2001 From: joelazar Date: Tue, 28 Apr 2026 13:10:06 +0200 Subject: [PATCH] :wrench: refactor trash handling with native commands - Refactor rm.fish: switch to `trash` command with proper argument parsing to ignore flags - Update custom-update: use AppleScript to empty Trash via Finder instead of rm -rf - Remove .local/share/Trash cleanup (macOS-only now) --- dot_config/private_fish/functions/rm.fish | 18 ++++++++++++++---- private_dot_local/bin/executable_custom-update | 9 ++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/dot_config/private_fish/functions/rm.fish b/dot_config/private_fish/functions/rm.fish index 46da08c2..a77cdbab 100644 --- a/dot_config/private_fish/functions/rm.fish +++ b/dot_config/private_fish/functions/rm.fish @@ -1,7 +1,17 @@ -function rm --description 'map rm to gio trash' - if string match -q -- '-*' $argv[1] - set argv[1] (string replace -a 'r' '' -- $argv[1]) +function rm --description 'map rm to macOS trash' + set -l args + set -l opts 1 + + for arg in $argv + test $opts -eq 1; and test "$arg" = --; and set opts 0; and continue + test $opts -eq 1; and string match -q -- '-*' "$arg"; and continue + set -a args $arg + end + + test (count $args) -gt 0; or begin + command trash --help + return 1 end - gio trash $argv + command trash $args end diff --git a/private_dot_local/bin/executable_custom-update b/private_dot_local/bin/executable_custom-update index 2db25b35..8ec4f32c 100644 --- a/private_dot_local/bin/executable_custom-update +++ b/private_dot_local/bin/executable_custom-update @@ -17,12 +17,7 @@ execute "brew cleanup" "Cleanup brew" execute "nvim --headless -c 'autocmd User MasonUpdateAllComplete qall' -c 'MasonUpdateAll'" "Update Neovim Mason packages" -ask_for_confirmation "Remove macOS Trash and .local/share/Trash directories?" +ask_for_confirmation "Empty macOS Trash?" if answer_is_yes; then - if [[ -d "$HOME/.Trash" ]]; then - execute "rm -rf $HOME/.Trash/{*,.*}" "Empty macOS Trash" - fi - if [[ -d "$HOME/.local/share/Trash" ]]; then - execute "rm -rf $HOME/.local/share/Trash/{*,.*}" "Empty .local/share/Trash" - fi + execute "osascript -e 'tell application \"Finder\" to empty trash'" "Empty macOS Trash" fi -- 2.51.2