die 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ree-1.8.7-2010.02@die
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ group :development do
4
+ gem "shoulda", ">= 0"
5
+ gem "bundler", "~> 1.0.0"
6
+ gem "jeweler", "~> 1.6.0"
7
+ gem "mocha"
8
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,22 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.6.4)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ metaclass (0.0.1)
10
+ mocha (0.10.0)
11
+ metaclass (~> 0.0.1)
12
+ rake (0.9.2.2)
13
+ shoulda (2.11.3)
14
+
15
+ PLATFORMS
16
+ ruby
17
+
18
+ DEPENDENCIES
19
+ bundler (~> 1.0.0)
20
+ jeweler (~> 1.6.0)
21
+ mocha
22
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Billy Reisinger
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.
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = die
2
+
3
+ Kill one or more processes matching a given name via an interactive script.
4
+
5
+ == Contributing to die
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Billy Reisinger. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "die"
18
+ gem.homepage = "http://github.com/unclebilly/die"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Kill one or more processes by command name}
21
+ gem.description = %Q{Kill one or more processes by command name via an interactive script. Die will find processes that match a given command name, and give you the opportunity to kill one, several, all, or none of them.}
22
+ gem.email = "billy.reisinger@gmail.com"
23
+ gem.authors = ["Billy Reisinger"]
24
+ gem.executables = ['die']
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/die ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
3
+ require 'die'
4
+
5
+ Die.new.run
data/die.gemspec ADDED
@@ -0,0 +1,63 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{die}
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 = ["Billy Reisinger"]
12
+ s.date = %q{2011-11-07}
13
+ s.default_executable = %q{die}
14
+ s.description = %q{Kill one or more processes by command name via an interactive script. Die will find processes that match a given command name, and give you the opportunity to kill one, several, all, or none of them.}
15
+ s.email = %q{billy.reisinger@gmail.com}
16
+ s.executables = ["die"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ ".rvmrc",
24
+ "Gemfile",
25
+ "Gemfile.lock",
26
+ "LICENSE.txt",
27
+ "README.rdoc",
28
+ "Rakefile",
29
+ "VERSION",
30
+ "bin/die",
31
+ "die.gemspec",
32
+ "lib/die.rb",
33
+ "test/helper.rb",
34
+ "test/test_die.rb"
35
+ ]
36
+ s.homepage = %q{http://github.com/unclebilly/die}
37
+ s.licenses = ["MIT"]
38
+ s.require_paths = ["lib"]
39
+ s.rubygems_version = %q{1.5.2}
40
+ s.summary = %q{Kill one or more processes by command name}
41
+
42
+ if s.respond_to? :specification_version then
43
+ s.specification_version = 3
44
+
45
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
46
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
47
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
48
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
49
+ s.add_development_dependency(%q<mocha>, [">= 0"])
50
+ else
51
+ s.add_dependency(%q<shoulda>, [">= 0"])
52
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
53
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
54
+ s.add_dependency(%q<mocha>, [">= 0"])
55
+ end
56
+ else
57
+ s.add_dependency(%q<shoulda>, [">= 0"])
58
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
59
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
60
+ s.add_dependency(%q<mocha>, [">= 0"])
61
+ end
62
+ end
63
+
data/lib/die.rb ADDED
@@ -0,0 +1,47 @@
1
+ class Die
2
+ def kill_phash_entry(entry)
3
+ pid = entry[0].strip.to_i
4
+ Process.kill("KILL", pid)
5
+ puts "Killed #{pid} #{entry[1]}"
6
+ end
7
+
8
+ def processes
9
+ @processes ||= `ps -ae -o pid,command | grep -i #{ARGV[0]} | egrep -v "(#{$0}|grep)"`.split("\n").map(&:strip)
10
+ end
11
+
12
+ # {
13
+ # 1 => ["1545", "/Applications/Firefox.app/Contents/MacOS/firefox-bin -psn_0_139298"],
14
+ # 2 => ["1546", "/Applications/Firefox.app/Contents/MacOS/firefox-bin -psn_0_139298"]
15
+ # }
16
+ def process_hash
17
+ p_hash = {}
18
+ processes.each_with_index do |p,i|
19
+ p_hash[i+1] = p.split
20
+ processes[i] = "#{i+1}.\t#{p[0..150]}"
21
+ end
22
+ p_hash
23
+ end
24
+
25
+ def run
26
+ unless processes.empty?
27
+ p_hash = process_hash
28
+
29
+ puts
30
+ puts processes
31
+ puts
32
+ puts " Type 'all' to kill 'em all, or the numbers (separated by a space) to kill some. Type anything else to quit."
33
+ inp = $stdin.gets.strip
34
+ if(inp =~ /^a(ll)?/i)
35
+ p_hash.each do |k,v|
36
+ kill_phash_entry(v)
37
+ end
38
+ elsif(inp =~ /[\d\s]{1,}/)
39
+ inp.split.each do |num|
40
+ kill_phash_entry(p_hash[num.to_i])
41
+ end
42
+ end
43
+ else
44
+ puts "No processes matching #{ARGV[0]}"
45
+ end
46
+ end
47
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+ require 'mocha'
13
+
14
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
15
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
16
+ require 'die'
17
+
18
+ class Test::Unit::TestCase
19
+ end
data/test/test_die.rb ADDED
@@ -0,0 +1,57 @@
1
+ require 'helper'
2
+
3
+ class TestDie < Test::Unit::TestCase
4
+ def setup
5
+ @out = $stdout
6
+ $stdout = StringIO.new
7
+ end
8
+
9
+ def teardown
10
+ $stdout = @out
11
+ end
12
+
13
+ def test_process_hash
14
+ d = Die.new
15
+ ps = [
16
+ "42 /usr/sbin/httpd -D FOREGROUND",
17
+ "249 /usr/sbin/httpd -D FOREGROUND"
18
+ ]
19
+ d.stubs(:processes).returns(ps)
20
+ expected = {
21
+ 1 => ["42", "/usr/sbin/httpd", "-D", "FOREGROUND"],
22
+ 2 => ["249", "/usr/sbin/httpd", "-D", "FOREGROUND"]
23
+ }
24
+ assert_equal(expected, d.process_hash)
25
+ end
26
+
27
+ def test_run_one_kill
28
+ d = Die.new
29
+ d.stubs(:processes).returns([
30
+ "42 /usr/sbin/httpd -D FOREGROUND",
31
+ "249 /usr/sbin/httpd -D FOREGROUND"
32
+ ])
33
+ d.stubs(:process_hash).returns({
34
+ 1 => ["42", "/usr/sbin/httpd", "-D", "FOREGROUND"],
35
+ 2 => ["249", "/usr/sbin/httpd", "-D", "FOREGROUND"]
36
+ })
37
+ $stdin.stubs(:gets).returns("1")
38
+ Process.expects(:kill).with("KILL", 42)
39
+ d.run
40
+ end
41
+
42
+ def test_run_multiple_kills
43
+ d = Die.new
44
+ d.stubs(:processes).returns([
45
+ "42 /usr/sbin/httpd -D FOREGROUND",
46
+ "249 /usr/sbin/httpd -D FOREGROUND"
47
+ ])
48
+ d.stubs(:process_hash).returns({
49
+ 1 => ["42", "/usr/sbin/httpd", "-D", "FOREGROUND"],
50
+ 2 => ["249", "/usr/sbin/httpd", "-D", "FOREGROUND"]
51
+ })
52
+ $stdin.stubs(:gets).returns("1 2")
53
+ Process.expects(:kill).with("KILL", 42)
54
+ Process.expects(:kill).with("KILL", 249)
55
+ d.run
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: die
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Billy Reisinger
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-07 00:00:00 -06:00
19
+ default_executable: die
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ version_requirements: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ prerelease: false
33
+ type: :development
34
+ requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: bundler
37
+ version_requirements: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ~>
41
+ - !ruby/object:Gem::Version
42
+ hash: 23
43
+ segments:
44
+ - 1
45
+ - 0
46
+ - 0
47
+ version: 1.0.0
48
+ prerelease: false
49
+ type: :development
50
+ requirement: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: jeweler
53
+ version_requirements: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ~>
57
+ - !ruby/object:Gem::Version
58
+ hash: 15
59
+ segments:
60
+ - 1
61
+ - 6
62
+ - 0
63
+ version: 1.6.0
64
+ prerelease: false
65
+ type: :development
66
+ requirement: *id003
67
+ - !ruby/object:Gem::Dependency
68
+ name: mocha
69
+ version_requirements: &id004 !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ prerelease: false
79
+ type: :development
80
+ requirement: *id004
81
+ description: Kill one or more processes by command name via an interactive script. Die will find processes that match a given command name, and give you the opportunity to kill one, several, all, or none of them.
82
+ email: billy.reisinger@gmail.com
83
+ executables:
84
+ - die
85
+ extensions: []
86
+
87
+ extra_rdoc_files:
88
+ - LICENSE.txt
89
+ - README.rdoc
90
+ files:
91
+ - .document
92
+ - .rvmrc
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE.txt
96
+ - README.rdoc
97
+ - Rakefile
98
+ - VERSION
99
+ - bin/die
100
+ - die.gemspec
101
+ - lib/die.rb
102
+ - test/helper.rb
103
+ - test/test_die.rb
104
+ has_rdoc: true
105
+ homepage: http://github.com/unclebilly/die
106
+ licenses:
107
+ - MIT
108
+ post_install_message:
109
+ rdoc_options: []
110
+
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ hash: 3
119
+ segments:
120
+ - 0
121
+ version: "0"
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ none: false
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ hash: 3
128
+ segments:
129
+ - 0
130
+ version: "0"
131
+ requirements: []
132
+
133
+ rubyforge_project:
134
+ rubygems_version: 1.5.2
135
+ signing_key:
136
+ specification_version: 3
137
+ summary: Kill one or more processes by command name
138
+ test_files: []
139
+