whichr 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/README +19 -8
  2. data/bin/whichr +15 -7
  3. data/lib/whichr.rb +52 -49
  4. metadata +19 -21
data/README CHANGED
@@ -10,9 +10,9 @@ Usage:
10
10
 
11
11
  C:\>whichr ruby
12
12
  higher in the list will be executed first
13
- ./ruby.bat
14
- C:/Ruby/bin/ruby.exe
15
- c:/cygwin/bin/ruby.exe
13
+ .\ruby.bat
14
+ C:\Ruby\bin\ruby.exe
15
+ c:\cygwin\bin\ruby.exe
16
16
 
17
17
  C:>whichr rub*
18
18
  higher in the list will be executed first
@@ -21,21 +21,32 @@ Usage:
21
21
  c:/ruby/bin/ruby.exe
22
22
  ...
23
23
 
24
+ C:>whichr rub* -a
25
+ higher in the list will be executed first
26
+
27
+
24
28
  Installation:
25
29
 
26
30
  C:\>gem install rogerdpack-whichr --source http://gems.github.com
31
+
32
+ Note: if you want it to run about 10x faster please see this post:
33
+ http://betterlogic.com/roger/?p=2364
27
34
 
28
35
  Enjoy.
29
36
 
30
37
  Feedback welcome rogerdpack on github/gmail
31
38
 
32
- Also Related:
39
+
40
+ Related projects:
41
+
42
+ If you're looking for a ruby library file, itself..
43
+
33
44
  http://github.com/Pistos/ruby-which discovers the location of installed ruby libraries, i.e. which gem folder they're in
45
+
34
46
  C:\>rwhich ruby-which
35
47
  c:/ruby/lib/ruby/gems/1.9.1/gems/Pistos-ruby-which-0.5.3/lib/ruby-which.rb
36
48
 
37
- Except you don't actually need it since you have
38
- $ gem which fileutils
39
- /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb
49
+ rubygems itself has a gem which command
40
50
 
41
- Thanks Eric!
51
+ $ gem which fileutils
52
+ /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/fileutils.rb
data/bin/whichr CHANGED
@@ -1,5 +1,7 @@
1
- # whichr
1
+ #!/usr/bin/ruby
2
+ # whichr gem
2
3
  # reveal executable name in path
4
+ #
3
5
  if $0 == __FILE__
4
6
  # test run
5
7
  $: << '../lib'
@@ -8,19 +10,25 @@ end
8
10
  require 'sane'
9
11
  require 'whichr.rb'
10
12
 
11
- if ARGV[0].in? ['--help', '-h']
12
- puts "syntax: executable_name or glob, ex: whichr or which* or whichr.bat
13
- [-a] for all (include non executables)
13
+ if ARGV[0].in?(['--help', '-h']) || (ARGV.length == 0)
14
+ puts
15
+ "syntax: executable_name_or_glob [-a for all (include non executables) ]
14
16
  ex:
15
17
  $ whichr ls
16
- $ whichr ls*
18
+ $ whichr ls\*
17
19
  $ whichr ls.exe
18
- $ whichr ls -a"
20
+ $ whichr ls -a # print non executables, too
21
+ "
19
22
  exit 0
20
23
  end
21
24
 
22
- if ARGV.include? '-a'
25
+
26
+ if ARGV[-1] == '-a'
23
27
  RubyWhich.new.which(ARGV[0..-2], true, true)
24
28
  else
25
29
  RubyWhich.new.which(ARGV, false, true)
26
30
  end
31
+
32
+ if File.exist? ARGV[0]
33
+ puts "warning: found parameter--you may need to escape your *'s in the command line, i.e. * becomes \\*"
34
+ end
data/lib/whichr.rb CHANGED
@@ -5,10 +5,13 @@ class RubyWhich
5
5
  # like ['abc'] (in windows, also searches for abc.bat)
6
6
  # or ['ab*'] (a glob, in windows, also reveals ab*.bat)
7
7
  def which( names, return_non_executables_too = false, realtime_output = false )
8
-
8
+
9
9
  puts "higher in the list is executed first" if realtime_output
10
-
10
+
11
11
  names = Array(names)
12
+ # on doze, you can't pass in * very easily
13
+ # it comes in as \*
14
+ names.map!{|name| name.dup.gsub('\*', '*') } if OS.windows?
12
15
 
13
16
  if OS.windows?
14
17
  for name in names.dup # avoid recursion
@@ -24,64 +27,64 @@ class RubyWhich
24
27
  path = ENV['PATH']
25
28
  # on windows add cwd
26
29
  path += (File::PATH_SEPARATOR + '.') if OS.windows?
27
-
30
+
28
31
  path.split(File::PATH_SEPARATOR).each do |dir|
29
-
32
+
30
33
  for name in names
31
34
  if OS.windows?
32
- names2 = Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
33
- unless return_non_executables_too
34
- names2 = names2.select{|name| File.executable?(name)} # only real execs
35
- end
36
- names2.collect!{|name| File.expand_path(name)} # get the right capitalization
35
+ names2 = Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
36
+ unless return_non_executables_too
37
+ names2 = names2.select{|name3| File.executable?(name3) && !File.directory?(name3)} # only real execs for doze
38
+ end
39
+ names2.collect!{|name| File.expand_path(name)} # get the right capitalization
37
40
  else
38
- names2 = Dir.glob(dir + '/' + name.strip)
39
- end
40
-
41
- # expand paths
42
- names2.collect!{|name| File.expand_path(name).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)}
43
-
44
- # make sure we aren't repeating a previous
45
- uniques = names2.select{|new|
46
- new = new.downcase if OS.windows?
47
- am_unique = true
48
- all_found.each{|old|
49
- old = old.downcase if OS.windows?
50
- if old == new
51
- am_unique = false
52
- break
53
- end
54
- }
55
- am_unique
56
- }
57
-
58
- if realtime_output
59
- uniques.each{ |file|
60
- print file
61
-
62
- if !File.executable? file
63
- print += ' (is not executable)'
64
- end
65
-
66
- if File.directory?(file)
67
- print ' (is a directory)'
68
- end
69
- puts
70
- }
71
- end
72
-
73
- all_found += uniques
74
-
41
+ names2 = Dir.glob(dir + '/' + name.strip)
42
+ end
43
+
44
+ # expand paths
45
+ names2.collect!{|name3| File.expand_path(name3).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)}
46
+
47
+ # make sure we aren't repeating a previous
48
+ uniques = names2.select{|new|
49
+ new = new.downcase if OS.windows?
50
+ am_unique = true
51
+ all_found.each{|old|
52
+ old = old.downcase if OS.windows?
53
+ if old == new
54
+ am_unique = false
55
+ break
56
+ end
57
+ }
58
+ am_unique
59
+ }
60
+
61
+ if realtime_output
62
+ uniques.each{ |file|
63
+ print file
64
+
65
+ if !File.executable? file
66
+ print ' (is not executable)'
67
+ end
68
+
69
+ if File.directory?(file)
70
+ print ' (is a directory)'
71
+ end
72
+ puts
73
+ }
74
+ end
75
+
76
+ all_found += uniques
77
+
75
78
  end
76
79
  end
77
-
80
+
78
81
  if realtime_output
79
82
  if all_found == []
80
- puts 'none found (' + names.inspect + ')'
83
+ puts 'none found (' + names.inspect + ')'
81
84
  end
82
85
  end
83
86
 
84
- all_found
87
+ all_found
85
88
  end
86
89
 
87
90
  end
metadata CHANGED
@@ -1,12 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whichr
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 3
9
- version: 0.3.3
4
+ version: 0.3.4
10
5
  platform: ruby
11
6
  authors:
12
7
  - Roger Pack
@@ -14,22 +9,29 @@ autorequire:
14
9
  bindir: bin
15
10
  cert_chain: []
16
11
 
17
- date: 2010-11-24 00:00:00 -07:00
12
+ date: 2009-12-23 00:00:00 -07:00
18
13
  default_executable:
19
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rdoc
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.3.0
24
+ version:
20
25
  - !ruby/object:Gem::Dependency
21
26
  name: sane
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
25
30
  requirements:
26
31
  - - ">="
27
32
  - !ruby/object:Gem::Version
28
- segments:
29
- - 0
30
33
  version: "0"
31
- type: :runtime
32
- version_requirements: *id001
34
+ version:
33
35
  description: windows friendly which command
34
36
  email:
35
37
  - rogerdpack@gmail.comm
@@ -53,25 +55,21 @@ rdoc_options: []
53
55
  require_paths:
54
56
  - lib
55
57
  required_ruby_version: !ruby/object:Gem::Requirement
56
- none: false
57
58
  requirements:
58
59
  - - ">="
59
60
  - !ruby/object:Gem::Version
60
- segments:
61
- - 0
62
61
  version: "0"
62
+ version:
63
63
  required_rubygems_version: !ruby/object:Gem::Requirement
64
- none: false
65
64
  requirements:
66
65
  - - ">="
67
66
  - !ruby/object:Gem::Version
68
- segments:
69
- - 0
70
67
  version: "0"
68
+ version:
71
69
  requirements: []
72
70
 
73
71
  rubyforge_project:
74
- rubygems_version: 1.3.7
72
+ rubygems_version: 1.3.5
75
73
  signing_key:
76
74
  specification_version: 3
77
75
  summary: windows friendly which command