Created
July 4, 2015 19:32
-
-
Save fukamachi/afc31d8ffc1ef0963bf5 to your computer and use it in GitHub Desktop.
which -- check if a command is available on the working environment
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
(defun which (command) | |
(handler-case | |
(let* ((result (with-output-to-string (s) | |
(uiop:run-program `("which" ,command) | |
:output s | |
:error-output *error-output*))) | |
(newline-pos | |
(position-if (lambda (char) | |
(or (char= char #\Newline) | |
(char= char #\Return))) | |
result))) | |
(if newline-pos | |
(subseq result 0 newline-pos) | |
result)) | |
(uiop:subprocess-error () | |
nil))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment