Skip to content

Instantly share code, notes, and snippets.

@fukamachi
Created July 4, 2015 19:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fukamachi/afc31d8ffc1ef0963bf5 to your computer and use it in GitHub Desktop.
Save fukamachi/afc31d8ffc1ef0963bf5 to your computer and use it in GitHub Desktop.
which -- check if a command is available on the working environment
(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