Skip to content

Instantly share code, notes, and snippets.

@keehun
Created March 14, 2012 14:32
Show Gist options
  • Save keehun/2036884 to your computer and use it in GitHub Desktop.
Save keehun/2036884 to your computer and use it in GitHub Desktop.
Command Line Deletion To Trash
function del() {
while [ -n "$1" ]; do
if [ ! -e "$1" ]; then
echo "'$1' not found; exiting"
return
fi
local file=`basename -- "$1"`
# Chop trailing '/' if there
file=${file%/}
local destination=''
if [ -e "$HOME/.Trash/$file" ]; then
# Extract file and extension
local ext=`expr "$file" : ".*\(\.[^\.]*\)$"`
local base=${file%$ext}
# Add a space between base and timestamp
test -n "$base" && base="$base "
destination="/$base`date +%H-%M-%S`_$RANDOM$ext"
fi
echo "Moving '$1' to '$HOME/.Trash$destination'"
\mv -i -- "$1" "$HOME/.Trash$destination" || return
shift
afplay /System/Library/Components/CoreAudio.component/Contents/SharedSupport/SystemSounds/finder/move\ to\ trash.aif
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment