-
Notifications
You must be signed in to change notification settings - Fork 0
/
darwin-trash
executable file
·40 lines (33 loc) · 973 Bytes
/
darwin-trash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/zsh
# This tool is so that I don’t need a 400-line shell script [1] or a 2k-line
# Objective-C program [2].
#
# [1]: https://github.com/morgant/tools-osx/blob/71c2db389c48cee8d03931eeb083cfc68158f7ed/src/trash
# [2]: https://github.com/ali-rantakari/trash
set -o errexit -o nounset -o pipefail
readonly COMMAND=${0:t} # only keep the Tail segment
function log-notice() {
logger "darwin-trash ($$) Notice: $*"
}
function main() {
if (( $# == 0 )) || [[ $# == 1 && $1 == (-h|--help) ]]
then
echo "Usage: $COMMAND <file>..."
return
fi
local arg
for arg
do
if [[ -f $arg || -d $arg ]]
then
log-notice "Trying to trash file: $arg"
# ${arg:a} resolves the Absolute path (logically)
osascript <<- EOF
tell application "Finder" to delete "${arg:a}" as POSIX file
EOF
log-notice "File trashed: $arg"
else logger -s -p user.warning "darwin-trash ($$) Warning: not a directory or regular file, skipping: $arg"
fi
done
}
main $@