rkill 0.0.1

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,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rvmrc ADDED
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ree-1.8.7-2011.03@rkill"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+
14
+ #
15
+ # First we attempt to load the desired environment directly from the environment
16
+ # file. This is very fast and efficient compared to running through the entire
17
+ # CLI and selector. If you want feedback on which environment was used then
18
+ # insert the word 'use' after --create as this triggers verbose mode.
19
+ #
20
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
21
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
22
+ then
23
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
24
+
25
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
26
+ then
27
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
28
+ fi
29
+ else
30
+ # If the environment file has not yet been created, use the RVM CLI to select.
31
+ if ! rvm --create "$environment_id"
32
+ then
33
+ echo "Failed to create RVM environment '${environment_id}'."
34
+ return 1
35
+ fi
36
+ fi
37
+
38
+ #
39
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
40
+ # it be automatically loaded. Uncomment the following and adjust the filename if
41
+ # necessary.
42
+ #
43
+ # filename=".gems"
44
+ # if [[ -s "$filename" ]]
45
+ # then
46
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
47
+ # fi
48
+
49
+ # If you use bundler, this might be useful to you:
50
+ # if command -v bundle && [[ -s Gemfile ]]
51
+ # then
52
+ # bundle install
53
+ # fi
54
+
55
+ if [[ $- == *i* ]] # check for interactive shells
56
+ then
57
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
58
+ else
59
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
60
+ fi
61
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rkill.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
4
+ require 'rkill'
5
+ require "rkill/cli"
6
+
7
+ Rkill::CLI.start
@@ -0,0 +1,13 @@
1
+ require 'ps'
2
+ require "rkill/version"
3
+
4
+ module Rkill
5
+ extend self
6
+
7
+ attr_writer :test
8
+
9
+ def test
10
+ @test ||= ENV['RKILL_TEST'] || ARGV.delete('--test')
11
+ end
12
+ end
13
+
@@ -0,0 +1,68 @@
1
+ module Rkill
2
+ BIN = "/bin/kill"
3
+ SIGNALS = `#{BIN} -l`.chomp.split(' ')
4
+ class CLI
5
+
6
+ def initialize opts
7
+ @opts = opts.dup.freeze
8
+ detect_type
9
+ end
10
+
11
+ def detect_type
12
+ indexes = []
13
+ indexes << @regex_index = @opts.find_index {|opt| opt =~ /^\/.+\/[imx]{0,3}$/}
14
+ indexes << @pcpu_index = @opts.find_index {|opt| opt =~ /^pcpu$/i}
15
+ indexes << @pmem_index = @opts.find_index {|opt| opt =~ /^pmem$/i}
16
+ indexes << @mem_index = @opts.find_index {|opt| opt =~ /^mem$/i}
17
+ @first_index = indexes.compact.min
18
+ end
19
+
20
+ def get_processes
21
+ return if @first_index.nil?
22
+ pcpu = eval(@opts[@pcpu_index+1]) if @pcpu_index
23
+
24
+ pmem = eval(@opts[@pmem_index+1]) if @pmem_index
25
+
26
+ mem = eval(@opts[@mem_index+1]) if @mem_index
27
+
28
+ regex = eval(@opts[@regex_index]) if @regex_index
29
+
30
+ processes = regex.nil? ? PS.all : PS(regex)
31
+
32
+ processes = processes.over :pcpu, pcpu if pcpu
33
+ processes = processes.over :pmem, pmem if pmem
34
+ processes = processes.over :mem, mem if mem
35
+
36
+ processes
37
+ end
38
+
39
+ def run!
40
+ command = BIN.dup << ' '
41
+
42
+ if @first_index.nil?
43
+ command << "'#{ARGV.join("' '")}'"
44
+ else
45
+ command << "'" << ARGV[0...@first_index].join("' '") << "' "
46
+ procs = get_processes.choose("Select processes to kill or hit enter to select all:")
47
+ pids = procs.collect {|proc| proc.pid if proc}.compact
48
+
49
+ abort if pids.empty?
50
+
51
+ command << pids.join(' ')
52
+ end
53
+
54
+ if Rkill.test
55
+ puts command
56
+ else
57
+ system(command)
58
+ end
59
+ end
60
+
61
+ class << self
62
+ def start
63
+ new(ARGV).run!
64
+ end
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module Rkill
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,26 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "rkill/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rkill"
7
+ s.version = Rkill::VERSION
8
+ s.authors = ["Tal Atlas"]
9
+ s.email = ["me@tal.by"]
10
+ s.homepage = "http://github.com/talby/rkill"
11
+ s.summary = %q{A replacement for the unix Kill command}
12
+ s.description = %q{A replacement for the unix Kill command}
13
+
14
+ s.rubyforge_project = "rkill"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.default_executable = %q{rkill}
20
+ s.require_paths = ["lib"]
21
+
22
+ # specify any dependencies here; for example:
23
+ s.add_development_dependency "rspec"
24
+ s.add_runtime_dependency "ps", '>= 0.0.6'
25
+ s.add_runtime_dependency "ansi"
26
+ end
@@ -0,0 +1,4 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'rkill'
4
+ require 'rspec'
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rkill
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tal Atlas
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-11-30 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &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
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: ps
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 19
43
+ segments:
44
+ - 0
45
+ - 0
46
+ - 6
47
+ version: 0.0.6
48
+ type: :runtime
49
+ version_requirements: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ name: ansi
52
+ prerelease: false
53
+ requirement: &id003 !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ type: :runtime
63
+ version_requirements: *id003
64
+ description: A replacement for the unix Kill command
65
+ email:
66
+ - me@tal.by
67
+ executables:
68
+ - rkill
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - .gitignore
75
+ - .rspec
76
+ - .rvmrc
77
+ - Gemfile
78
+ - Rakefile
79
+ - bin/rkill
80
+ - lib/rkill.rb
81
+ - lib/rkill/cli.rb
82
+ - lib/rkill/version.rb
83
+ - rkill.gemspec
84
+ - spec/spec_helper.rb
85
+ homepage: http://github.com/talby/rkill
86
+ licenses: []
87
+
88
+ post_install_message:
89
+ rdoc_options: []
90
+
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ hash: 3
99
+ segments:
100
+ - 0
101
+ version: "0"
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ hash: 3
108
+ segments:
109
+ - 0
110
+ version: "0"
111
+ requirements: []
112
+
113
+ rubyforge_project: rkill
114
+ rubygems_version: 1.8.8
115
+ signing_key:
116
+ specification_version: 3
117
+ summary: A replacement for the unix Kill command
118
+ test_files:
119
+ - spec/spec_helper.rb
120
+ has_rdoc: