From 9938b4f417f6e668f6a176030df8088a0b11f0b0 Mon Sep 17 00:00:00 2001
From: mattmc3 <mattmc3@gmail.com>
Date: Tue, 12 Dec 2023 11:59:16 -0500
Subject: [PATCH] osx: Add trash function

---
 modules/osx/functions/trash | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 modules/osx/functions/trash

diff --git a/modules/osx/functions/trash b/modules/osx/functions/trash
new file mode 100644
index 00000000..0efa2154
--- /dev/null
+++ b/modules/osx/functions/trash
@@ -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"
+
+# }