Created
January 11, 2010 15:45
-
-
Save minitau/274316 to your computer and use it in GitHub Desktop.
which_on_windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
ruby -S -x "%0.cmd" %* | |
goto end | |
#!ruby -Ks | |
paths = ENV['PATH'].split(';') | |
pathexts = ENV['PATHEXT'].split(';') | |
cmd, = ARGV.shift | |
re = Regexp.union(*pathexts.map{|ext| Regexp.new("^#{cmd}#{ext}$", Regexp::IGNORECASE)}) | |
paths.each do |path| | |
begin | |
puts Dir.entries(path).select{|item|re.match(item)}.map{|item|"#{path}/#{item}"} | |
rescue | |
end | |
end | |
__END__ | |
:end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
paths = ENV['PATH'].split(';') | |
pathexts = ENV['PATHEXT'].split(';') | |
cmd, = ARGV.shift | |
re = Regexp.union(*pathexts.map{|ext| Regexp.new("^#{cmd}#{ext}$", Regexp::IGNORECASE)}) | |
paths.each do |path| | |
puts Dir.entries(path).select{|item|re.match(item)}.map{|item|"#{path}/item"} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment