From 28da8f916b3e237f90e9536e299e353247d0930d Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 18 Jan 2012 22:02:23 -0500 Subject: [PATCH] Use Finder to trash files to enable Put Back. Though AppleScript is slow, Put Back data is stored in ~/.Trash/.DS_Store, and there is no way to write to it from the shell at this time. The minimum Zsh version has been incremented to 4.3.10 to use the 'a' modifier to convert a relative path into a full path. --- init.zsh | 2 +- plugins/osx/functions/trash | 31 +++++++++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/init.zsh b/init.zsh index 82f2e214..20d38abb 100644 --- a/init.zsh +++ b/init.zsh @@ -1,7 +1,7 @@ # Initializes Oh My Zsh. # Check for the minimum supported version. -min_zsh_version=4.3.9 +min_zsh_version='4.3.10' if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then print "omz: The minimum supported Zsh version is $min_zsh_version." fi diff --git a/plugins/osx/functions/trash b/plugins/osx/functions/trash index 9a7bf587..33c0f6d5 100644 --- a/plugins/osx/functions/trash +++ b/plugins/osx/functions/trash @@ -1,13 +1,20 @@ -local trash_dir="${HOME}/.Trash" -local trash_item -local item -for item in "${@}"; do - if [[ -e "${item}" ]] || [[ -L "${item}" ]]; then - trash_item="${trash_dir}/${item:t}" - if [[ -e "${trash_item}" ]] || [[ -L "${trash_item}" ]]; then - trash_item="${trash_item} $(date "+%H-%M-%S")" - fi - mv -f "${item}" "${trash_item}" - fi -done +print -N "${@:a}" | xargs -0 osascript -e ' + on run theFilePaths + tell application "Finder" + set thePOSIXFiles to {} + repeat with aFilePath in theFilePaths + set aPOSIXFile to aFilePath as POSIX file + if exists aPOSIXFile + set end of thePOSIXFiles to aPOSIXFile + end if + end repeat + move every item of thePOSIXFiles to trash + end tell + end run +' &>/dev/null + +if (( $? != 0)); then + print "$0: failed to move one or more items" >&2 + return 1 +fi