crux-env-path-fix 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown ADDED
@@ -0,0 +1,3 @@
1
+ # env-path-fix.rb to ease your __export PATH=/some/dir/here/:${PATH}__ pains
2
+
3
+ lorem ....
data/bin/env-path-fix ADDED
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'env-path-fix'
4
+
5
+ Operations = {
6
+ '$' => :append,
7
+ "+" => :prepend, "^" => :prepend,
8
+ "-" => :remove, "--" => :remove_re
9
+ }
10
+
11
+ def main *args
12
+ op = args.shift || :clean
13
+ op = Operations[op] || op
14
+ path = EnvPathFix.new.send op, *args
15
+ puts path
16
+ rescue => e
17
+ puts "#{e}"
18
+ $stderr.puts <<-EOT
19
+
20
+ usage:
21
+ #{$0} (prepend | remove | append) <args> ...
22
+ #{$0} clean
23
+
24
+ EOT
25
+ puts ENV['PATH']
26
+ exit -1
27
+ end
28
+
29
+ main *ARGV
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "env-path-fix"
3
+ gem.version = "0.1.2"
4
+ gem.date = "2009-01-03"
5
+ gem.summary = "making PATH ENV var manipulation easy"
6
+ gem.email = "env-path-fix.rb@sebrink.de"
7
+ gem.homepage = "http://github.com/crux/env-path-fix"
8
+ gem.description = "ruby script to append, prepend, remove, remove by regexp and remove duplicate entries from PATH (shell) variable. Use it to simplify environment setup from shell scripts"
9
+ gem.authors = ["dirk l. sebrink"]
10
+ gem.files = %w(
11
+ README.markdown
12
+ env-path-fix.gemspec
13
+ lib/env-path-fix.rb
14
+ bin/env-path-fix
15
+ )
16
+ gem.executables << 'env-path-fix'
17
+ gem.test_files = ["test/test_pathfix.rb"]
18
+ gem.has_rdoc = true
19
+ gem.rdoc_options = ["--main", "README.markdown"]
20
+ gem.extra_rdoc_files = ["README.markdown"]
21
+ #gem.add_dependency("open4", ["> 0.0.0"])
22
+ end
@@ -0,0 +1,40 @@
1
+ # EnvPathFix
2
+ #
3
+ class EnvPathFix
4
+
5
+ require 'pathname'
6
+
7
+ def initialize
8
+ @a = (ENV['PATH'].split ':').map { |p| Pathname.new(p).cleanpath.to_s }
9
+ clean
10
+ end
11
+
12
+ def append(*args)
13
+ @a.push(*args)
14
+ self.clean
15
+ end
16
+
17
+ def prepend(*args)
18
+ @a.unshift(*args)
19
+ self.clean
20
+ end
21
+
22
+ def remove(*args)
23
+ args.each { |e| @a.delete e }
24
+ self.clean
25
+ end
26
+
27
+ def remove_re(*args)
28
+ args.each { |re| @a.delete_if { |e| e.match(re) } }
29
+ self.clean
30
+ end
31
+
32
+ def clean
33
+ @a.uniq!
34
+ self
35
+ end
36
+
37
+ def to_s
38
+ @a.uniq.join ':'
39
+ end
40
+ end
@@ -0,0 +1,15 @@
1
+ require 'test/unit'
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), "..", "lib")
4
+
5
+ require 'env-path-fix'
6
+
7
+ class TestEnvPathFix < Test::Unit::TestCase
8
+ def setup
9
+ end
10
+
11
+ def test_new
12
+ assert_not_nil epf = EnvPathFix.new
13
+ end
14
+ end
15
+
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crux-env-path-fix
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - dirk l. sebrink
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-03 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ruby script to append, prepend, remove, remove by regexp and remove duplicate entries from PATH (shell) variable. Use it to simplify environment setup from shell scripts
17
+ email: env-path-fix.rb@sebrink.de
18
+ executables:
19
+ - env-path-fix
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.markdown
24
+ files:
25
+ - README.markdown
26
+ - env-path-fix.gemspec
27
+ - lib/env-path-fix.rb
28
+ - bin/env-path-fix
29
+ has_rdoc: true
30
+ homepage: http://github.com/crux/env-path-fix
31
+ post_install_message:
32
+ rdoc_options:
33
+ - --main
34
+ - README.markdown
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: "0"
42
+ version:
43
+ required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ requirements: []
50
+
51
+ rubyforge_project:
52
+ rubygems_version: 1.2.0
53
+ signing_key:
54
+ specification_version: 2
55
+ summary: making PATH ENV var manipulation easy
56
+ test_files:
57
+ - test/test_pathfix.rb