trash 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Lee Jones
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,36 @@
1
+ = Trash
2
+
3
+ When it's too hard to say goodbye... an alternative to `rm`.
4
+
5
+ A simple command line utility to move files/folders to a "trash" folder before deleting them.
6
+
7
+ == Usage
8
+
9
+ From the command line:
10
+
11
+ trash potentially-important-file.txt
12
+
13
+ Handles multiple files with the same name
14
+
15
+ trash ~/Documents/Groceries/shopping-list.txt
16
+ trash ~/Documents/Christmas/shopping-list.txt
17
+ trash ~/Documents/AutoParts/shopping-list.txt
18
+
19
+ Trash folder will contain:
20
+ * shopping-list.txt # originally ~/Documents/Groceries/shopping-list.txt
21
+ * shopping-list01.txt # originally ~/Documents/Christmas/shopping-list.txt
22
+ * shopping-list02.txt # originally ~/Documents/AutoParts/shopping-list.txt
23
+
24
+ == Note on Patches/Pull Requests
25
+
26
+ * Fork the project.
27
+ * Make your feature addition or bug fix.
28
+ * Add tests for it. This is important so I don't break it in a
29
+ future version unintentionally.
30
+ * Commit, do not mess with rakefile, version, or history.
31
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
32
+ * Send me a pull request. Bonus points for topic branches.
33
+
34
+ == Copyright
35
+
36
+ Copyright (c) 2010 Lee Jones. See LICENSE for details.
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "trash"
8
+ gem.summary = %Q{trash can for the command line}
9
+ gem.description = %Q{when its hard to say goodbye, and rm is just too much... use trash instead.}
10
+ gem.email = "scribblethink@gmail.com"
11
+ gem.homepage = "http://github.com/leejones/trash"
12
+ gem.authors = ["Lee Jones"]
13
+ gem.add_development_dependency "rspec", ">= 1.2.9"
14
+ gem.add_development_dependency "cucumber", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'spec/rake/spectask'
23
+ Spec::Rake::SpecTask.new(:spec) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.spec_files = FileList['spec/**/*_spec.rb']
26
+ end
27
+
28
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
29
+ spec.libs << 'lib' << 'spec'
30
+ spec.pattern = 'spec/**/*_spec.rb'
31
+ spec.rcov = true
32
+ end
33
+
34
+ task :spec => :check_dependencies
35
+
36
+ begin
37
+ require 'cucumber/rake/task'
38
+ Cucumber::Rake::Task.new(:features)
39
+
40
+ task :features => :check_dependencies
41
+ rescue LoadError
42
+ task :features do
43
+ abort "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
44
+ end
45
+ end
46
+
47
+ task :default => :spec
48
+
49
+ require 'rake/rdoctask'
50
+ Rake::RDocTask.new do |rdoc|
51
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
52
+
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = "trash #{version}"
55
+ rdoc.rdoc_files.include('README*')
56
+ rdoc.rdoc_files.include('lib/**/*.rb')
57
+ end
data/TODO ADDED
File without changes
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
+
4
+ require 'trash'
5
+
6
+ exit Trash.new.throw_out(*ARGV)
@@ -0,0 +1 @@
1
+ default: --format profile features
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + '/../../lib')
2
+ require 'trash'
3
+
4
+ require 'spec/expectations'
@@ -0,0 +1,9 @@
1
+ Feature: something something
2
+ In order to something something
3
+ A user something something
4
+ something something something
5
+
6
+ Scenario: something something
7
+ Given inspiration
8
+ When I create a sweet new gem
9
+ Then everyone should see how awesome I am
@@ -0,0 +1,53 @@
1
+ require 'fileutils'
2
+
3
+ class Trash
4
+ attr_reader :errors
5
+ attr_accessor :trashcan
6
+
7
+ def initialize(options = {})
8
+ @trashcan = options[:trashcan].nil? ? "#{ENV['HOME']}/.Trash" : options[:trashcan]
9
+ create_trashcan_if_absent
10
+ @errors = []
11
+ end
12
+
13
+ def has_trashcan?
14
+ File.directory? @trashcan
15
+ end
16
+
17
+ def throw_out(paths)
18
+ paths.each do |path|
19
+ path = File.expand_path(path)
20
+ if File.exist? path
21
+ FileUtils.mv(path, "#{ENV['HOME']}/.Trash/#{unique_file_name(path)}")
22
+ else
23
+ add_error "#{path} does not exist. Please check the file path."
24
+ return 1
25
+ end
26
+ end
27
+
28
+ return 0
29
+ end
30
+
31
+ def add_error(error)
32
+ @errors << error
33
+ end
34
+
35
+ private
36
+
37
+ def create_trashcan_if_absent
38
+ FileUtils.mkdir_p @trashcan unless has_trashcan?
39
+ end
40
+
41
+ def unique_file_name(path)
42
+ path_name = File.basename(path)
43
+ path_extension = File.extname(path)
44
+ if (File.exists?("#{ENV['HOME']}/.Trash/#{path_name}"))
45
+ count = 1
46
+ while File.exists?("#{ENV['HOME']}/.Trash/#{path_name.gsub(path_extension, "0#{count}#{path_extension}")}")
47
+ count += 1
48
+ end
49
+ new_path_name = path_name.gsub(path_extension, "0#{count}#{path_extension}")
50
+ end
51
+ return new_path_name
52
+ end
53
+ end
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,9 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'trash'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+
7
+ Spec::Runner.configure do |config|
8
+
9
+ end
@@ -0,0 +1,130 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Trash" do
4
+ def delete(file)
5
+ `if [ -e #{file} ]; then rm -rf #{file}; fi;`
6
+ end
7
+
8
+ def delete_from_trash(file)
9
+ delete("#{ENV['HOME']}/.Trash/#{file}")
10
+ end
11
+
12
+ def trash_should_contain(file_name)
13
+ File.exist?("#{ENV['HOME']}/.Trash/#{file_name}").should == true
14
+ end
15
+
16
+ def trash_should_contain_directory(directory_name)
17
+ File.directory?(directory_name)
18
+ trash_should_contain(directory_name)
19
+ end
20
+
21
+ def tmp_should_not_contain(file_name)
22
+ File.exist?("/tmp/#{file_name}").should == false
23
+ end
24
+
25
+ it "moves a file to the trash" do
26
+ `echo 'default text' > /tmp/testing.txt`
27
+ Trash.new.throw_out("/tmp/testing.txt")
28
+ tmp_should_not_contain "testing.txt"
29
+ trash_should_contain "testing.txt"
30
+ delete_from_trash "testing.txt"
31
+ end
32
+
33
+ it "moves multiple files to the trash" do
34
+ `echo 'default text first' > /tmp/testing.txt`
35
+ `echo 'default text second' > /tmp/testing2.txt`
36
+ Trash.new.throw_out(["/tmp/testing.txt", "/tmp/testing2.txt"])
37
+ tmp_should_not_contain "testing.txt"
38
+ tmp_should_not_contain "testing2.txt"
39
+ trash_should_contain "testing.txt"
40
+ trash_should_contain "testing2.txt"
41
+ delete_from_trash "testing.txt"
42
+ delete_from_trash "testing2.txt"
43
+ end
44
+
45
+ it "should handle spaces in the file/folder name" do
46
+ create_file = `echo "Test with spaces..." > "/tmp/test with spaces.txt"`
47
+ Trash.new.throw_out("/tmp/test with spaces.txt")
48
+ tmp_should_not_contain "test with spaces.txt"
49
+ trash_should_contain "test with spaces.txt"
50
+ delete_from_trash "\"test with spaces.txt\""
51
+ end
52
+
53
+ it "appends a number to the filename if a file with same name already exisits in trash" do
54
+ `echo 'default text' > /tmp/testing.txt`
55
+ Trash.new.throw_out("/tmp/testing.txt")
56
+ tmp_should_not_contain "testing.txt"
57
+ trash_should_contain "testing.txt"
58
+ original = File.new("/Users/leejones/.Trash/testing.txt", "r")
59
+ original.read.should == "default text\n"
60
+
61
+ `echo 'testing different file with same name' > /tmp/testing.txt`
62
+ Trash.new.throw_out("/tmp/testing.txt")
63
+ tmp_should_not_contain "testing.txt"
64
+ trash_should_contain "testing01.txt"
65
+ third = File.new("/Users/leejones/.Trash/testing01.txt", "r")
66
+ third.read.should == "testing different file with same name\n"
67
+
68
+ `echo 'testing different file 2 with same name' > /tmp/testing.txt`
69
+ Trash.new.throw_out("/tmp/testing.txt")
70
+ tmp_should_not_contain "testing.txt"
71
+ trash_should_contain "testing02.txt"
72
+ fourth = File.new("/Users/leejones/.Trash/testing02.txt", "r")
73
+ fourth.read.should == "testing different file 2 with same name\n"
74
+
75
+ `echo 'testing different file 3 with same name' > /tmp/testing.txt`
76
+ Trash.new.throw_out("/tmp/testing.txt")
77
+ tmp_should_not_contain "testing.txt"
78
+ trash_should_contain "testing03.txt"
79
+ fifth = File.new("/Users/leejones/.Trash/testing03.txt", "r")
80
+ fifth.read.should == "testing different file 3 with same name\n"
81
+
82
+ delete_from_trash "testing.txt"
83
+ delete_from_trash "testing01.txt"
84
+ delete_from_trash "testing02.txt"
85
+ delete_from_trash "testing03.txt"
86
+ end
87
+
88
+ it "should throw an error when file does not exist" do
89
+ tmp_should_not_contain "not_a_file.txt"
90
+ trash = Trash.new
91
+ trash.throw_out("/tmp/not_a_file.txt").should == 1
92
+ trash.errors.join(' ').should == "/tmp/not_a_file.txt does not exist. Please check the file path."
93
+ end
94
+
95
+ it "moves a directory to the trash" do
96
+ dir = `mkdir -p /tmp/testdir01`
97
+ Trash.new.throw_out("/tmp/testdir01")
98
+ tmp_should_not_contain "testdir01"
99
+ trash_should_contain_directory "testdir01"
100
+ delete_from_trash "testdir01"
101
+ end
102
+
103
+ it "moves multiple directories to the trash" do
104
+ dirs = `mkdir -p /tmp/testdir01 /tmp/testdir02`
105
+ Trash.new.throw_out(["/tmp/testdir01", "/tmp/testdir02"])
106
+ tmp_should_not_contain "testdir01"
107
+ tmp_should_not_contain "testdir02"
108
+ trash_should_contain_directory "testdir01"
109
+ trash_should_contain_directory "testdir02"
110
+ delete_from_trash "testdir01"
111
+ delete_from_trash "testdir02"
112
+ end
113
+
114
+ describe "trashcan" do
115
+ it "finds the trashcan" do
116
+ FileUtils.mkdir_p "#{ENV['HOME']}/.Trash"
117
+ Trash.new.has_trashcan?.should == true
118
+ end
119
+
120
+ it "creates a trashcan if one does not exist" do
121
+ delete("/tmp/test_trash_can")
122
+ File.exist?("/tmp/test_trash_can").should == false
123
+ oscar = Trash.new({:trashcan => "/tmp/test_trash_can"})
124
+ File.exist?("/tmp/test_trash_can").should == true
125
+ File.directory?("/tmp/test_trash_can").should == true
126
+ delete("/tmp/test_trash_can")
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,67 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{trash}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Lee Jones"]
12
+ s.date = %q{2010-03-25}
13
+ s.default_executable = %q{trash}
14
+ s.description = %q{when its hard to say goodbye, and rm is just too much... use trash instead.}
15
+ s.email = %q{scribblethink@gmail.com}
16
+ s.executables = ["trash"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE",
19
+ "README.rdoc",
20
+ "TODO"
21
+ ]
22
+ s.files = [
23
+ ".document",
24
+ ".gitignore",
25
+ "LICENSE",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "TODO",
29
+ "VERSION",
30
+ "bin/trash",
31
+ "config/cucumber.yml",
32
+ "features/step_definitions/trash_steps.rb",
33
+ "features/support/env.rb",
34
+ "features/trash.feature",
35
+ "lib/trash.rb",
36
+ "spec/spec.opts",
37
+ "spec/spec_helper.rb",
38
+ "spec/trash_spec.rb",
39
+ "trash.gemspec"
40
+ ]
41
+ s.homepage = %q{http://github.com/leejones/trash}
42
+ s.rdoc_options = ["--charset=UTF-8"]
43
+ s.require_paths = ["lib"]
44
+ s.rubygems_version = %q{1.3.6}
45
+ s.summary = %q{trash can for the command line}
46
+ s.test_files = [
47
+ "spec/spec_helper.rb",
48
+ "spec/trash_spec.rb"
49
+ ]
50
+
51
+ if s.respond_to? :specification_version then
52
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
57
+ s.add_development_dependency(%q<cucumber>, [">= 0"])
58
+ else
59
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
60
+ s.add_dependency(%q<cucumber>, [">= 0"])
61
+ end
62
+ else
63
+ s.add_dependency(%q<rspec>, [">= 1.2.9"])
64
+ s.add_dependency(%q<cucumber>, [">= 0"])
65
+ end
66
+ end
67
+
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trash
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - Lee Jones
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-25 00:00:00 -04:00
18
+ default_executable: trash
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 1
29
+ - 2
30
+ - 9
31
+ version: 1.2.9
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: cucumber
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: when its hard to say goodbye, and rm is just too much... use trash instead.
47
+ email: scribblethink@gmail.com
48
+ executables:
49
+ - trash
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - LICENSE
54
+ - README.rdoc
55
+ - TODO
56
+ files:
57
+ - .document
58
+ - .gitignore
59
+ - LICENSE
60
+ - README.rdoc
61
+ - Rakefile
62
+ - TODO
63
+ - VERSION
64
+ - bin/trash
65
+ - config/cucumber.yml
66
+ - features/step_definitions/trash_steps.rb
67
+ - features/support/env.rb
68
+ - features/trash.feature
69
+ - lib/trash.rb
70
+ - spec/spec.opts
71
+ - spec/spec_helper.rb
72
+ - spec/trash_spec.rb
73
+ - trash.gemspec
74
+ has_rdoc: true
75
+ homepage: http://github.com/leejones/trash
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 0
96
+ version: "0"
97
+ requirements: []
98
+
99
+ rubyforge_project:
100
+ rubygems_version: 1.3.6
101
+ signing_key:
102
+ specification_version: 3
103
+ summary: trash can for the command line
104
+ test_files:
105
+ - spec/spec_helper.rb
106
+ - spec/trash_spec.rb