Skip to content

Instantly share code, notes, and snippets.

@ne-sachirou
Last active December 15, 2015 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ne-sachirou/5229362 to your computer and use it in GitHub Desktop.
Save ne-sachirou/5229362 to your computer and use it in GitHub Desktop.
*nix `which` command on Windows (need Ruby).
@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
@ne-sachirou
Copy link
Author

Windos版whichコマンド (*nix which command on Windows (need Ruby).) - c4se記:さっちゃんですよ☆ http://c4se.hatenablog.com/entry/2013/03/24/061210

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment