From 3bf9ccd530dfb0e835d4cc584ef1e6d3979dac49 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sun, 12 Apr 2020 21:13:47 +0200 Subject: [PATCH] Add which example --- examples/which.clj | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100755 examples/which.clj diff --git a/examples/which.clj b/examples/which.clj new file mode 100755 index 00000000..fbd9666c --- /dev/null +++ b/examples/which.clj @@ -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)))