-
-
Save mgk/874878 to your computer and use it in GitHub Desktop.
commmand line rm replacement in ruby that uses OS X Trash
This file contains hidden or 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/rm 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. | |
| require 'fileutils' | |
| now = Time.now | |
| dir = File.expand_path("~/.Trash") + "/rm-#{now.strftime('%Y-%m-%d-%H')}-#{rand(1000000)}" | |
| Dir.mkdir(dir) | |
| ARGV.each do |f| | |
| if File.symlink?(f) | |
| puts "removing symlink" | |
| 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