Skip to content

Commit

Permalink
osx: Add trash function
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmc3 authored and indrajitr committed Apr 5, 2024
1 parent 6bf4505 commit 085ab11
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions modules/osx/functions/trash
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#
# Moves files to the macOS trash.
#

# function trash {

emulate -L zsh
setopt LOCAL_OPTIONS EXTENDED_GLOB

local file
local -a files=()
for file in $@; do
if [[ -e $file ]]; then
# ':a' gets the full path (do not use ':A', which would resolve symlinks)
files+=("the POSIX file \"${file:a}\"")
else
print "trash: No such file or directory '$file'." >&2
return 1
fi
done

if (( $#files == 0 )); then
print 'usage: trash <files...>' >&2
return 64 # Match rm's return code.
fi

# Join file list with commas, and tell Finder to trash that list.
local file_list="${(pj., .)files}"
osascript 2>&1 > /dev/null -e "tell app \"Finder\" to move { "${file_list}" } to trash"

# }

0 comments on commit 085ab11

Please sign in to comment.