-
-
Save javascripter/177415 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env ruby | |
# vim: ft=ruby | |
def mk_uniq_name_by(filename, path) | |
uniq_name = filename | |
prefix = 0 | |
while FileTest.exist?(File.join(path, uniq_name)) | |
prefix += 1 | |
uniq_name = sprintf("%d.%s", prefix, filename) | |
end | |
uniq_name | |
end | |
def die(*args) | |
$stderr.printf(*args) | |
exit(1) | |
end | |
def trash(filename) | |
die("No such file or directory: %s\n", filename) unless FileTest.exist?(filename) | |
trash_path = File.expand_path("~/.Trash") | |
basename = File.basename(filename) | |
newname = mk_uniq_name_by(basename, trash_path) | |
File.rename(filename, File.join(trash_path, newname)) | |
end | |
ARGV.each {|filename| | |
trash(filename) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment