Last active
March 7, 2016 07:06
-
-
Save ctgnauh/868ee9762d9127852ef2 to your computer and use it in GitHub Desktop.
shell trash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
help() | |
{ | |
cat << HELP | |
usage: mm [-h -v] file1 file2 file3 ... fileN | |
-d: DEBUG mode | |
-h: Print this message | |
HELP | |
exit 0 | |
} | |
print_info() | |
{ | |
if [ -z "$quiet" ]; then | |
echo $info | |
fi | |
} | |
if [ -z "$TRASH_PATH" ]; then | |
TRASH_PATH="$HOME/trash" | |
fi | |
while [ -n "$1" ]; do | |
case "$1" in | |
-h) help;shift 1;; | |
-q) quiet=1; shift 1;; | |
--) shift;break;; | |
-*) help;exit 0;; | |
*) break;; | |
esac | |
done | |
for file in $*; do | |
fullpath="$TRASH_PATH/$file" | |
if [ -e "$fullpath" ]; then | |
info="$file is already in the trash." && print_info | |
mv -i "$file" "$TRASH_PATH" | |
else | |
info="mm move $file to $TRASH_PATH" && print_info | |
mv "$file" "$TRASH_PATH" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment