Created
June 14, 2021 10:26
-
-
Save fwg/ef2b28d06aee83f4823e69e026fa859d to your computer and use it in GitHub Desktop.
Windows which
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 | |
php %USERPROFILE%\bin\winwhich.php %* |
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
<?php | |
$PATH = explode(';', getenv('PATH')); | |
$PATHEXT = explode(';', getenv('PATHEXT')); | |
$showCandidates = false; | |
$file = ''; | |
array_shift($argv); | |
foreach ($argv as $arg) { | |
if ($arg == '--show-candidates') { | |
$showCandidates = true; | |
} else { | |
$file = $arg; | |
} | |
} | |
if (empty($file)) { | |
echo 'No file given!', PHP_EOL; | |
return 1; | |
} | |
array_unshift($PATHEXT, ''); | |
$candidates = array(); | |
foreach ($PATHEXT as $ext) { | |
$fn = $file . $ext; | |
foreach ($PATH as $p) { | |
$candidates[] = $p . '\\' . $fn; | |
} | |
} | |
foreach ($candidates as $c) { | |
$exists = file_exists($c); | |
if ($showCandidates) { | |
echo ($exists ? 'yes' : 'no '), ' ', $c, PHP_EOL; | |
} elseif (!$showCandidates && $exists) { | |
echo $c, PHP_EOL; | |
} | |
} | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment