Skip to content

Commit

Permalink
Add windows? predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
borkdude committed Mar 11, 2022
1 parent e58be7c commit 49abb26
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/babashka/fs.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
(def ^:const file-separator File/separator)
(def ^:const path-separator File/pathSeparator)

(def ^:private windows?
(def ^:private win?
(-> (System/getProperty "os.name")
(str/lower-case)
(str/includes? "win")))
Expand All @@ -257,7 +257,7 @@
([root pattern] (match root pattern nil))
([root pattern {:keys [hidden follow-links max-depth recursive]}]
(let [base-path (-> root absolutize normalize)
base-path (if windows?
base-path (if win?
(str/replace base-path file-separator (str "\\" file-separator))
base-path)
skip-hidden? (not hidden)
Expand All @@ -266,7 +266,7 @@
[prefix pattern] (str/split pattern #":")
pattern (str base-path
;; we need to escape the file separator on Windows
(when windows? "\\")
(when win? "\\")
file-separator
pattern)
pattern (str prefix ":" pattern)
Expand Down Expand Up @@ -766,7 +766,7 @@
([program opts]
;; :win-exts is unsupported, if you read and use
;; this, let me know, it may break.
(let [exts (if windows?
(let [exts (if win?
(let [exts (or (:win-exts opts)
["com" "exe" "bat" "cmd"])
ext (extension program)]
Expand Down Expand Up @@ -983,3 +983,8 @@
(home (subs path-str 1))
(path (home (subs path-str 1 sep)) (subs path-str (inc sep)))))
(as-path f))))

(defn windows?
"Returns true if OS is Windows."
[]
(str/starts-with? (System/getProperty "os.name") "Windows"))

0 comments on commit 49abb26

Please sign in to comment.