path_manager 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e00c22ee7ca017f8380e2b53171e1216a6a395ca
4
+ data.tar.gz: b15574bff8400e37a41fb7b9a71aaad39ae00374
5
+ SHA512:
6
+ metadata.gz: 6cc87f317502d1bf733b7b15a2096098275c226de206c5484a9202a7bf496270e9f8dc4002c0688742c5c329de2708a3ad91658e767e62608aa5c9c7e801c336
7
+ data.tar.gz: 522beb1822c34113392f7c9e5c86e855ead4968920c918473ed90ef6320f525e22eed9864e82b394b1d12200ce2c50c2e8191f94c7476b8bd7f1b723531ae150
data/.gitignore ADDED
@@ -0,0 +1,46 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ # Created by http://www.gitignore.io
24
+
25
+ ### OSX ###
26
+ .DS_Store
27
+ .AppleDouble
28
+ .LSOverride
29
+
30
+ # Icon must end with two \r
31
+ Icon
32
+
33
+
34
+ # Thumbnails
35
+ ._*
36
+
37
+ # Files that might appear on external disk
38
+ .Spotlight-V100
39
+ .Trashes
40
+
41
+ # Directories potentially created on remote AFP share
42
+ .AppleDB
43
+ .AppleDesktop
44
+ Network Trash Folder
45
+ Temporary Items
46
+ .apdisk
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in path_manager.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Charley Hutchison
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # PathManager
2
+
3
+ Helps you manage your PATH variable.
4
+
5
+ ## Installation
6
+
7
+
8
+ $ gem install path_manager
9
+
10
+ ## Usage
11
+
12
+ ### Listing your path
13
+ $ path_manager list
14
+
15
+ ### Prepending directories to your path
16
+ $ path_manager prepend DIRECTORY
17
+
18
+ ### Appending directories to your path
19
+ $ path_manager append DIRECTORY
20
+
21
+ ### Show locations of a program in your path
22
+ $ path_manager which PROGRAM
23
+
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/glenwayguy/path_manager/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/path_manager ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'path_manager'
4
+
5
+ PathManager::PathManager.start(ARGV)
data/lib/config.json ADDED
@@ -0,0 +1,32 @@
1
+ {
2
+ "zsh": [
3
+ "~/.zshrc",
4
+ "/etc/profile",
5
+ "~/.profile",
6
+ "/etc/zshenv",
7
+ "/etc/zprofile",
8
+ "/etc/zshrc",
9
+ "/etc/zlogin",
10
+ "/etc/zlogout",
11
+ "~/.zshenv",
12
+ "~/.zprofile",
13
+ "~/.zlogin"
14
+ ],
15
+ "bash": [
16
+ "/etc/profile",
17
+ "~/.profile",
18
+ "~/.bash_profile",
19
+ "~/.bash_login",
20
+ "~/.bash_logout",
21
+ "~/.bashrc"
22
+ ],
23
+ "sh": [
24
+ "/etc/profile",
25
+ "~/.profile"
26
+ ],
27
+ "ksh": [
28
+ "/etc/profile",
29
+ "~/.profile",
30
+ "~/.kshrc"
31
+ ]
32
+ }
@@ -0,0 +1,3 @@
1
+ module PathManager
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,120 @@
1
+ require "path_manager/version"
2
+
3
+ module PathManager
4
+ require 'thor'
5
+ require 'json'
6
+ class PathManager < Thor
7
+ include Thor::Actions
8
+ no_commands do
9
+ def get_path_location
10
+ file = File.read("./config.json")
11
+ configs = JSON.parse(file, symbolize_names: true)
12
+ regex = /Shell: \/bin\/([a-zA-Z\/]*)/i
13
+ info = %x[finger `whoami`]
14
+ shell = info.match(regex)
15
+ shell = shell.captures.first
16
+ paths = configs[shell.to_sym]
17
+ paths.map! { |e| File.expand_path(e) }
18
+ search = /^(?:export )?PATH=/
19
+ location = {}
20
+ catch :done do
21
+ paths.each_with_index do |path, index|
22
+ if File.exists?(path)
23
+ File.open(path) do |f|
24
+ path_found = f.each_line.detect.with_index do |line, index2|
25
+ if search.match(line)
26
+ location[:path] = paths[index]
27
+ location[:line] = (index2 + 1)
28
+ true
29
+ else
30
+ false
31
+ end
32
+ end
33
+ throw :done if path_found
34
+ end
35
+ end
36
+ end
37
+ end
38
+ location
39
+ end
40
+ end
41
+
42
+ desc "list", "Lists the directories in your PATH variable."
43
+ def list
44
+ say "This is your current $PATH:"
45
+ path_items = ENV['PATH'].split(":")
46
+ path_items.each_with_index do |item, index|
47
+ if index < 9
48
+ say "#{index+1}. #{item}"
49
+ else
50
+ say "#{index+1}. #{item}"
51
+ end
52
+ end
53
+ end
54
+ desc "prepend DIRECTORY", "Prepends the directory to your PATH variable"
55
+ def prepend(path)
56
+ path = path.to_s
57
+ location = get_path_location
58
+ File.open(location[:path], "r+") do |file|
59
+ while (location[:line] -= 1) > 0
60
+ end
61
+ pos = file.pos
62
+ regex = /((?:\/|~).+)/
63
+ path_items = file.gets.match(regex).captures.first.split(":")
64
+ if path_items.last == "$PATH"
65
+ path_items.pop
66
+ end
67
+ path_items.unshift(path)
68
+ path_items = path_items.join(":")
69
+ rest = file.read
70
+ file.seek pos
71
+ final_path = "export PATH=" + path_items + ":$PATH\n"
72
+ file.write "export PATH=" + path_items + ":$PATH\n"
73
+ file.write rest
74
+ end
75
+ end
76
+ desc "append DIRECTORY", "Appends the directory to your PATH variable"
77
+ def append(path)
78
+ path = path.to_s
79
+ location = get_path_location
80
+ File.open(location[:path], "r+") do |file|
81
+ while (location[:line] -= 1) > 0
82
+ end
83
+ pos = file.pos
84
+ regex = /((?:\/|~).+)/
85
+ path_items = file.gets.match(regex).captures.first.split(":")
86
+ if path_items.last == "$PATH"
87
+ path_items.pop
88
+ end
89
+ path_items.push(path)
90
+ path_items = path_items.join(":")
91
+ rest = file.read
92
+ file.seek pos
93
+ final_path = "export PATH=" + path_items + ":$PATH\n"
94
+ file.write "export PATH=" + path_items + ":$PATH\n"
95
+ file.write rest
96
+ end
97
+ end
98
+
99
+ desc "which PROGRAM", "Shows the the different path entry where the program appears. Like which, but not just with the first location"
100
+ def which(program)
101
+ program = program.to_s
102
+ say("Warning: If you use rbenv, then the order may be incorrect for gems.", :red)
103
+ path = ENV["PATH"]
104
+ path = path.split(":")
105
+ directories = []
106
+ path.each do |dir|
107
+ if Dir.exists?(dir)
108
+ entries = Dir.entries(dir)
109
+ directories.push(dir.to_s + "/" + program) if entries.include?(program)
110
+ end
111
+ end
112
+ directories.each_with_index do |dir, index|
113
+ say "#{index+1}. #{dir}"
114
+ end
115
+ end
116
+
117
+ end
118
+
119
+
120
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'path_manager/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "path_manager"
8
+ spec.version = PathManager::VERSION
9
+ spec.authors = ["Charley Hutchison"]
10
+ spec.email = ["charley@charleyhutchison.com"]
11
+ spec.summary = %q{Helps manage your $PATH variable.}
12
+ spec.description = %q{Helps manage your $PATH variable.}
13
+ spec.homepage = "http://github.com/glenwayguy/path_manager"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ["path_manager"]
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "thor", "~> 0.19"
22
+ spec.add_dependency "json", "~> 1.8"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: path_manager
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Charley Hutchison
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.19'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.19'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Helps manage your $PATH variable.
70
+ email:
71
+ - charley@charleyhutchison.com
72
+ executables:
73
+ - path_manager
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/path_manager
83
+ - lib/config.json
84
+ - lib/path_manager.rb
85
+ - lib/path_manager/version.rb
86
+ - path_manager.gemspec
87
+ homepage: http://github.com/glenwayguy/path_manager
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Helps manage your $PATH variable.
111
+ test_files: []