-
-
Save mgk/10542026 to your computer and use it in GitHub Desktop.
OS X rm Trash wrapper
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 | |
# 'rm' replacement that integrates with OS X Trash | |
# | |
# To install: save as ~/bin/rm, make executable, and put ~/bin first in your PATH | |
# | |
# Copyright (c) Michael Keirnan | |
# Disclaimer: Provided as-is, no warranty, may work, may not, be careful, don't run with scissors, etc. | |
# | |
# A lot of things like build tools shell out to rm. This has not caused me problems after several years of use | |
# although sometimes I see the verbose rm outut when I don't expect it. YMMV. | |
require 'fileutils' | |
now = Time.now | |
dir = File.expand_path("~/.Trash") + "/rm-#{now.strftime('%Y-%m-%d-%H-%M-%S.%L')}-#{rand(1000000)}" | |
Dir.mkdir(dir) | |
ARGV.each do |f| | |
if File.symlink?(f) | |
FileUtils::Verbose.rm(f) | |
end | |
if File.exist?(f) | |
FileUtils::Verbose.mv(f, dir) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment