Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Command line tool for Gnome users to send something to the Trash (with restore info). | ||
# TODO: Support trashing files of the same name. | ||
class Janitor | ||
|
||
TRASH_DIR = File.expand_path(File.join(ENV['HOME'], '.local/share/Trash')) | ||
FILES_DIR = File.join(TRASH_DIR, 'files') | ||
INFO_DIR = File.join(TRASH_DIR, 'info') | ||
|
||
class << self | ||
def sweep!(files = []) | ||
files.each { |file| trash!(file) } | ||
end | ||
|
||
def trash!(file) | ||
return unless File.exists?(file) | ||
$stdout.puts "Trashing #{file}" | ||
create_info_for(file) | ||
move_to_trash(file) | ||
end | ||
|
||
private | ||
|
||
def create_info_for(file) | ||
info_file = File.join(INFO_DIR, "#{file}.trashinfo") | ||
raise "Info file exists for #{file}: #{info_file}" if File.exists?(info_file) | ||
|
||
deletion_date = Time.now.strftime("%Y-%m-%dT%H:%M:%S") | ||
|
||
File.open(info_file, 'w') do |info| | ||
info.puts "[Trash Info]" | ||
info.puts "Path=#{File.expand_path(file)}" | ||
info.puts "DeletionDate=#{deletion_date}" | ||
end | ||
end | ||
|
||
def move_to_trash(file) | ||
system "mv #{file} #{FILES_DIR}" | ||
end | ||
|
||
end # self | ||
end # Janitor | ||
|
||
|
||
if __FILE__ == $0 | ||
if ARGV.empty? | ||
$stderr.puts "No file(s) given!\n" | ||
$stderr.puts "Usage: #{File.basename($0)} <file1>..<fileN>" | ||
exit | ||
end | ||
|
||
Janitor.sweep!(ARGV) | ||
end |
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
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