Last active
December 15, 2015 08:18
-
-
Save ne-sachirou/5229362 to your computer and use it in GitHub Desktop.
*nix `which` command on Windows (need Ruby).
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 | |
rem setlocal | |
rem for %%t in (%1) do echo,%%~$path:t | |
rem for %%e in (%pathext%) do ( | |
rem for %%t in (%1%%e) do echo,%%~$path:t | |
rem ) | |
rem endlocal | |
ruby -x %~f0 %* | |
@goto end | |
#!ruby | |
# encoding=utf-8 | |
# `which` command in Windows. | |
# author: ne_Sachirou <utakata.c4se@gmail.com> | |
# date: 2013 | |
# License: Public Domain | |
target = ARGV[0] | |
path = ENV['path'].split ';' | |
pathext = ',' + ENV['pathext'].split(';').join(',').downcase | |
path.each do |dir| | |
Dir.chdir dir rescue next | |
files = Dir["#{target}{#{pathext}}"] | |
if files.any? | |
puts "#{dir}#{dir =~ /\\$/ ? '' : '\\'}#{files.first}" | |
break | |
end | |
end | |
:end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Windos版whichコマンド (*nix
which
command on Windows (need Ruby).) - c4se記:さっちゃんですよ☆ http://c4se.hatenablog.com/entry/2013/03/24/061210