whichr 0.1.8

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 +41 -0
  2. data/bin/whichr +26 -0
  3. data/lib/whichr.rb +72 -0
  4. metadata +67 -0
data/README ADDED
@@ -0,0 +1,41 @@
1
+ ruby which: the linux "which" command re-written in ruby [and windows-friendly].
2
+
3
+ An executable locator (i.e. which or locate command) for windows that works!
4
+
5
+ Itch it scratches: there seems to be a lack of a "which" command for windows that actually work--they sometimes skip batch files entirely [batch file? what's that?] or don't list extensions, leaving you in doubt. Despite running "which yyy" you never know what you're really running when you next run yyy in the command line--is it yyy.exe or some other yyy.bat that wasn't reported by "which"?
6
+
7
+ Try it--you might really like it.
8
+
9
+ Usage:
10
+
11
+ C:\>whichr ruby
12
+ higher in the list will be executed first
13
+ ./ruby.bat
14
+ C:/Ruby/bin/ruby.exe
15
+ c:/cygwin/bin/ruby.exe
16
+
17
+ C:>whichr rub*
18
+ higher in the list will be executed first
19
+ c:/ruby/bin/rubigen
20
+ c:/ruby/bin/rubigen.bat
21
+ c:/ruby/bin/ruby.exe
22
+ ...
23
+
24
+ Installation:
25
+
26
+ C:\>gem install rogerdpack-whichr --source http://gems.github.com
27
+
28
+ Enjoy.
29
+
30
+ Feedback welcome rogerdpack on github/gmail
31
+
32
+ Also Related:
33
+ http://github.com/Pistos/ruby-which discovers the location of installed ruby libraries, i.e. which gem folder they're in
34
+ C:\>rwhich ruby-which
35
+ c:/ruby/lib/ruby/gems/1.9.1/gems/Pistos-ruby-which-0.5.3/lib/ruby-which.rb
36
+
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
40
+
41
+ Thanks Eric!
data/bin/whichr ADDED
@@ -0,0 +1,26 @@
1
+ # whichr
2
+ # reveal executable name in path
3
+ if $0 == __FILE__
4
+ # test run
5
+ $: << '../lib'
6
+ require 'rubygems'
7
+ end
8
+ require 'sane'
9
+ require 'whichr.rb'
10
+
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)
14
+ ex:
15
+ $ whichr ls
16
+ $ whichr ls*
17
+ $ whichr ls.exe
18
+ $ whichr ls -a"
19
+ exit 0
20
+ end
21
+
22
+ if ARGV.include? '-a'
23
+ RubyWhich.new.process(ARGV[0..-2], true)
24
+ else
25
+ RubyWhich.new.process(ARGV, false)
26
+ end
data/lib/whichr.rb ADDED
@@ -0,0 +1,72 @@
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, return_non_executables_too = false )
11
+ names = [names] unless names.is_a? Array
12
+
13
+ if RUBY_PLATFORM =~ /mswin|mingw/
14
+ for name in names.dup # avoid recursion
15
+ # windows compat.
16
+ for extension in ENV['PATHEXT'].split(';') do
17
+ names << name + extension
18
+ end
19
+ end
20
+ end
21
+
22
+ all_found = []
23
+ path = ENV['PATH']
24
+ # on windows add . [the cwd]
25
+ path += (File::PATH_SEPARATOR + '.') if RUBY_PLATFORM =~ /mswin|mingw/
26
+ path.split(File::PATH_SEPARATOR).each do |dir|
27
+ for name in names
28
+ if RUBY_PLATFORM =~ /mswin|mingw/
29
+ names2 = Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
30
+ unless return_non_executables_too
31
+ names2 = names2.select{|name| File.executable?(name)} # only real execs
32
+ end
33
+ names2.collect!{|name| File.expand_path(name)} # get the right capitalization
34
+ else
35
+ names2 = Dir.glob(dir + '/' + name.strip)
36
+ end
37
+
38
+ all_found += names2.collect{|name| File.expand_path(name)}
39
+ end
40
+ end
41
+
42
+ all_found.uniq
43
+ end
44
+
45
+ def process(names, all = false)
46
+ candidates = which(names, all)
47
+ if candidates == []
48
+ puts 'none found (' + names.inspect + ')'
49
+ else
50
+ print output(candidates)
51
+ end
52
+ end
53
+
54
+ def output all
55
+ output = "higher in the list is executed first\n"
56
+ for candidate in all
57
+ # might just match the name and not be executable
58
+ candidate = Dir.glob(candidate + '*')[0] if RUBY_PLATFORM =~ /mswin|mingw/ # get the right capitalization in doze
59
+ output << candidate
60
+ if !File.executable? candidate
61
+ output += ' (is not executable)'
62
+ if(File.directory?(candidate))
63
+ output << ' (is a directory)'
64
+ end
65
+ end
66
+ output << "\n"
67
+ end
68
+ output
69
+ end
70
+
71
+
72
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: whichr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.8
5
+ platform: ruby
6
+ authors:
7
+ - Roger Pack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-29 00:00:00 -06:00
13
+ default_executable:
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:
25
+ description: windows friendly which command
26
+ email:
27
+ - rogerdpack@gmail.comm
28
+ executables:
29
+ - whichr
30
+ extensions: []
31
+
32
+ extra_rdoc_files: []
33
+
34
+ files:
35
+ - bin/whichr
36
+ - lib/whichr.rb
37
+ - README
38
+ has_rdoc: true
39
+ homepage: http://github.com/rogerdpack/which_ruby
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project:
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: windows friendly which command
66
+ test_files: []
67
+