Skip to content

Instantly share code, notes, and snippets.

@minitau
Created January 11, 2010 15:45
Show Gist options
  • Save minitau/274316 to your computer and use it in GitHub Desktop.
Save minitau/274316 to your computer and use it in GitHub Desktop.
which_on_windows
@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
#!/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