Add which example
This commit is contained in:
parent
61b7cb8321
commit
3bf9ccd530
1 changed files with 17 additions and 0 deletions
17
examples/which.clj
Executable file
17
examples/which.clj
Executable file
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/usr/bin/env bb
|
||||||
|
|
||||||
|
(require '[clojure.java.io :as io])
|
||||||
|
|
||||||
|
(defn where [executable]
|
||||||
|
(let [path (System/getenv "PATH")
|
||||||
|
paths (.split path (System/getProperty "path.separator"))]
|
||||||
|
(loop [paths paths]
|
||||||
|
(when-first [p paths]
|
||||||
|
(let [f (io/file p executable)]
|
||||||
|
(if (and (.isFile f)
|
||||||
|
(.canExecute f))
|
||||||
|
(.getCanonicalPath f)
|
||||||
|
(recur (rest paths))))))))
|
||||||
|
|
||||||
|
(when-let [executable (first *command-line-args*)]
|
||||||
|
(println (where executable)))
|
||||||
Loading…
Reference in a new issue