Permalink
Browse files

hopefully the new one works well

  • Loading branch information...
1 parent b558a49 commit b1353242b1ca86029f6379abb51ac00c5c79453b @rdp committed Nov 24, 2010
Showing with 70 additions and 59 deletions.
  1. +14 −7 bin/whichr
  2. +52 −49 lib/whichr.rb
  3. +4 −3 whichr.gemspec
View
21 bin/whichr
@@ -1,5 +1,7 @@
-# whichr
+#!/usr/bin/ruby
+# whichr gem
# reveal executable name in path
+#
if $0 == __FILE__
# test run
$: << '../lib'
@@ -8,19 +10,24 @@ end
require 'sane'
require 'whichr.rb'
-if ARGV[0].in? ['--help', '-h']
- puts "syntax: executable_name or glob, ex: whichr or which* or whichr.bat
- [-a] for all (include non executables)
+if ARGV[0].in?(['--help', '-h']) || (ARGV.length == 0)
+ puts "syntax:
+whichr executable_name_or_glob [-a : all (include non executables) ]
ex:
$ whichr ls
- $ whichr ls*
+ $ whichr ls\*
$ whichr ls.exe
- $ whichr ls -a"
+ $ whichr ls -a # print non executables, too"
exit 0
end
-if ARGV.include? '-a'
+
+if ARGV[-1] == '-a'
RubyWhich.new.which(ARGV[0..-2], true, true)
else
RubyWhich.new.which(ARGV, false, true)
end
+
+if File.exist? ARGV[0]
+ puts "warning: found parameter--you may need to escape your *'s in the command line, i.e. * becomes \\*"
+end
View
101 lib/whichr.rb
@@ -5,10 +5,13 @@ class RubyWhich
# like ['abc'] (in windows, also searches for abc.bat)
# or ['ab*'] (a glob, in windows, also reveals ab*.bat)
def which( names, return_non_executables_too = false, realtime_output = false )
-
+
puts "higher in the list is executed first" if realtime_output
-
+
names = Array(names)
+ # on doze, you can't pass in * very easily
+ # it comes in as \*
+ names.map!{|name| name.dup.gsub('\*', '*') } if OS.windows?
if OS.windows?
for name in names.dup # avoid recursion
@@ -24,64 +27,64 @@ def which( names, return_non_executables_too = false, realtime_output = false )
path = ENV['PATH']
# on windows add cwd
path += (File::PATH_SEPARATOR + '.') if OS.windows?
-
+
path.split(File::PATH_SEPARATOR).each do |dir|
-
+
for name in names
if OS.windows?
- names2 = Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
- unless return_non_executables_too
- names2 = names2.select{|name| File.executable?(name)} # only real execs
- end
- names2.collect!{|name| File.expand_path(name)} # get the right capitalization
+ names2 = Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
+ unless return_non_executables_too
+ names2 = names2.select{|name3| File.executable?(name3) && !File.directory?(name3)} # only real execs for doze
+ end
+ names2.collect!{|name| File.expand_path(name)} # get the right capitalization
else
- names2 = Dir.glob(dir + '/' + name.strip)
- end
-
- # expand paths
- names2.collect!{|name| File.expand_path(name).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)}
-
- # make sure we aren't repeating a previous
- uniques = names2.select{|new|
- new = new.downcase if OS.windows?
- am_unique = true
- all_found.each{|old|
- old = old.downcase if OS.windows?
- if old == new
- am_unique = false
- break
- end
- }
- am_unique
- }
-
- if realtime_output
- uniques.each{ |file|
- print file
-
- if !File.executable? file
- print += ' (is not executable)'
- end
-
- if File.directory?(file)
- print ' (is a directory)'
- end
- puts
- }
- end
-
- all_found += uniques
-
+ names2 = Dir.glob(dir + '/' + name.strip)
+ end
+
+ # expand paths
+ names2.collect!{|name3| File.expand_path(name3).gsub(File::SEPARATOR, File::ALT_SEPARATOR || File::SEPARATOR)}
+
+ # make sure we aren't repeating a previous
+ uniques = names2.select{|new|
+ new = new.downcase if OS.windows?
+ am_unique = true
+ all_found.each{|old|
+ old = old.downcase if OS.windows?
+ if old == new
+ am_unique = false
+ break
+ end
+ }
+ am_unique
+ }
+
+ if realtime_output
+ uniques.each{ |file|
+ print file
+
+ if !File.executable? file
+ print ' (is not executable)'
+ end
+
+ if File.directory?(file)
+ print ' (is a directory)'
+ end
+ puts
+ }
+ end
+
+ all_found += uniques
+
end
end
-
+
if realtime_output
if all_found == []
- puts 'none found (' + names.inspect + ')'
+ puts 'none found (' + names.inspect + ')'
end
end
- all_found
+ all_found
end
end
View
7 whichr.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = %q{whichr}
- s.version = "0.3.2"
+ s.version = "0.3.6"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Roger Pack"]
@@ -10,9 +10,10 @@ Gem::Specification.new do |s|
s.homepage = %q{http://github.com/rogerdpack/which_ruby}
s.executable = 'whichr'
s.require_paths = ["lib"]
- s.add_dependency(%q<rdoc>, [">= 2.3.0"]) # so that I don't need a lib directory :P
- s.add_dependency(%q<sane>) # Object.in?
+# s.add_dependency(%q<rdoc>, [">= 2.3.0"]) # so that I don't need a lib directory :P hmm...
+ s.add_dependency(%q<sane>) # Object.in? etc.
+# 0.3.6 bump to the gem 0.3.5 version, remove rdoc dependency
# 0.3.1 cleanup inline
# 0.3.0 inline

0 comments on commit b135324

Please sign in to comment.