rogerdpack-whichr 0.1.3 → 0.1.4

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.
Files changed (3) hide show
  1. data/bin/whichr +18 -42
  2. data/lib/whichr.rb +35 -0
  3. metadata +3 -3
data/bin/whichr CHANGED
@@ -1,50 +1,26 @@
1
- # stolen from the gnuplot gem
2
- # and then modified
1
+ # whichr
2
+ # reveal executable name in path
3
3
  require 'rubygems'
4
4
  require 'sane'
5
+ require 'whichr.rb'
5
6
 
6
- if(ARGV[0].in?( ['-h', '--help'])) || !ARGV[0]
7
- puts 'syntax: nameary_name'
8
- else
9
- puts 'higher in the list will be executed first'
10
- def which( names )
11
- success = false
12
- path = ENV['PATH']
13
- # on windows add . [cwd]
14
- path += ('.' + File::PATH_SEPARATOR) if RUBY_PLATFORM =~ /mswin|mingw/
15
-
16
- path.split(File::PATH_SEPARATOR).each do |dir|
17
- for name in names
18
- candidates = Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
19
- for candidate in candidates
20
- # might just match the name and not be executable
21
- candidate = Dir.glob(candidate + '*')[0] if RUBY_PLATFORM =~ /mswin|mingw/ # get the right capitalization in doze
22
- if File::executable?(candidate)
23
- print candidate
24
- if(File.directory?(candidate))
25
- print ' (is a directory)'
26
- end
27
- success = true
28
- puts
29
- elsif File::exist? candidate
30
- puts candidate + ' (is not executable)'
31
- end
32
- end
33
- end
34
- end
35
-
36
- return success
37
- end
7
+ if ARGV[0].in? ['--help', '-h']
8
+ puts "syntax: executable_name or glob"
9
+ exit 0
10
+ end
38
11
 
39
- list = [ARGV[0]]
12
+ all = RubyWhich.new.which([ARGV[0]])
40
13
 
41
- if RUBY_PLATFORM =~ /mswin|mingw/
42
- # windows compat.
43
- for extension in ENV['PATHEXT'].split(';') do
44
- list << ARGV[0] + extension
14
+ for candidate in all
15
+ # might just match the name and not be executable
16
+ candidate = Dir.glob(candidate + '*')[0] if RUBY_PLATFORM =~ /mswin|mingw/ # get the right capitalization in doze
17
+ if File::executable?(candidate)
18
+ print candidate
19
+ if(File.directory?(candidate))
20
+ print ' (is a directory)'
45
21
  end
22
+ puts
23
+ elsif File::exist? candidate
24
+ puts candidate + ' (is not executable)'
46
25
  end
47
-
48
- which(list)
49
-
50
26
  end
data/lib/whichr.rb ADDED
@@ -0,0 +1,35 @@
1
+ # stolen from the gnuplot gem
2
+ # and then modified
3
+ require 'rubygems'
4
+ require 'sane'
5
+
6
+ class RubyWhich
7
+ # search the path for the given names
8
+ # like ['abc'] (in windows, also searches for abc.bat)
9
+ # or ['ab*'] (a glob, in windows, also reveals ab*.bat)
10
+ def which( names )
11
+
12
+ if RUBY_PLATFORM =~ /mswin|mingw/
13
+ for name in names.dup # avoid recursion
14
+ # windows compat.
15
+ for extension in ENV['PATHEXT'].split(';') do
16
+ names << name + extension
17
+ end
18
+ end
19
+ end
20
+
21
+ all_found = []
22
+ path = ENV['PATH']
23
+ # on windows add . [the cwd]
24
+ path += ('.' + File::PATH_SEPARATOR) if RUBY_PLATFORM =~ /mswin|mingw/
25
+
26
+ path.split(File::PATH_SEPARATOR).each do |dir|
27
+ for name in names
28
+ all_found += Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
29
+ end
30
+ end
31
+
32
+ all_found
33
+ end
34
+
35
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rogerdpack-whichr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Pack
@@ -43,10 +43,10 @@ extra_rdoc_files: []
43
43
 
44
44
  files:
45
45
  - bin/whichr
46
+ - lib/whichr.rb
46
47
  - README
47
48
  has_rdoc: false
48
49
  homepage: http://github.com/rogerdpack/which_ruby
49
- licenses:
50
50
  post_install_message:
51
51
  rdoc_options: []
52
52
 
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
67
  requirements: []
68
68
 
69
69
  rubyforge_project:
70
- rubygems_version: 1.3.5
70
+ rubygems_version: 1.2.0
71
71
  signing_key:
72
72
  specification_version: 2
73
73
  summary: windows friendly which command