rogerdpack-whichr 0.1.2 → 0.1.3
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.
- data/bin/whichr +6 -8
- metadata +1 -1
data/bin/whichr
CHANGED
@@ -4,19 +4,21 @@ require 'rubygems'
|
|
4
4
|
require 'sane'
|
5
5
|
|
6
6
|
if(ARGV[0].in?( ['-h', '--help'])) || !ARGV[0]
|
7
|
-
puts 'syntax:
|
7
|
+
puts 'syntax: nameary_name'
|
8
8
|
else
|
9
9
|
puts 'higher in the list will be executed first'
|
10
|
-
def which
|
10
|
+
def which( names )
|
11
11
|
success = false
|
12
12
|
path = ENV['PATH']
|
13
13
|
# on windows add . [cwd]
|
14
14
|
path += ('.' + File::PATH_SEPARATOR) if RUBY_PLATFORM =~ /mswin|mingw/
|
15
15
|
|
16
16
|
path.split(File::PATH_SEPARATOR).each do |dir|
|
17
|
-
for
|
18
|
-
candidates = Dir.glob(dir.gsub("\\", "/") + '/' +
|
17
|
+
for name in names
|
18
|
+
candidates = Dir.glob(dir.gsub("\\", "/") + '/' + name.strip)
|
19
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
|
20
22
|
if File::executable?(candidate)
|
21
23
|
print candidate
|
22
24
|
if(File.directory?(candidate))
|
@@ -31,10 +33,6 @@ else
|
|
31
33
|
end
|
32
34
|
end
|
33
35
|
|
34
|
-
# This is an implementation that works when the which command is
|
35
|
-
# available.
|
36
|
-
#
|
37
|
-
# IO.popen("which #{bin}") { |io| return io.readline.chomp }
|
38
36
|
return success
|
39
37
|
end
|
40
38
|
|