|
82 | 82 |
|
83 | 83 | (validate-path path current-dir allowed-dirs))) |
84 | 84 |
|
85 | | - (defn- babashka-shebang? |
86 | | - [file-path] |
87 | | - (when (path-exists? file-path) |
88 | | - (try |
89 | | - (with-open [r (io/reader file-path)] |
90 | | - (let [line (-> r line-seq first)] |
91 | | - (and line |
92 | | - (or (str/starts-with? line "#!/usr/bin/env bb") |
93 | | - (str/starts-with? line "#!/usr/bin/bb") |
94 | | - (str/starts-with? line "#!/bin/bb"))))) |
95 | | - (catch Exception _ false)))) |
96 | | - |
97 | | - (defn clojure-file? |
98 | | - "Checks if a file path has a Clojure-related extension or Babashka shebang." |
99 | | - |
| 85 | +(defn- babashka-shebang? |
| 86 | + [file-path] |
| 87 | + (when (path-exists? file-path) |
| 88 | + (try |
| 89 | + (with-open [r (io/reader file-path)] |
| 90 | + (let [line (-> r line-seq first)] |
| 91 | + (and line |
| 92 | + (re-matches #"^#!/[^\s]+/(bb|env\s{1,3}bb)(\s.*)?$" line)))) |
| 93 | + (catch Exception _ false)))) |
| 94 | + |
| 95 | +(defn clojure-file? |
| 96 | + "Checks if a file path has a Clojure-related extension or Babashka shebang. |
| 97 | + |
100 | 98 | Supported extensions: |
101 | 99 | - .clj (Clojure) |
102 | 100 | - .cljs (ClojureScript) |
103 | 101 | - .cljc (Clojure/ClojureScript shared) |
104 | 102 | - .bb (Babashka) |
105 | 103 | - .edn (Extensible Data Notation) |
106 | 104 | - .lpy (Librepl) |
| 105 | + |
107 | 106 | Also detects files starting with a Babashka shebang (`bb`)." |
108 | | - [file-path] |
109 | | - (when file-path |
110 | | - (let [lower-path (str/lower-case file-path)] |
111 | | - (or (str/ends-with? lower-path ".clj") |
112 | | - (str/ends-with? lower-path ".cljs") |
113 | | - (str/ends-with? lower-path ".cljc") |
114 | | - (str/ends-with? lower-path ".bb") |
115 | | - (str/ends-with? lower-path ".lpy") |
116 | | - (str/ends-with? lower-path ".edn") |
117 | | - (babashka-shebang? file-path))))) |
| 107 | + [file-path] |
| 108 | + (when file-path |
| 109 | + (let [lower-path (str/lower-case file-path)] |
| 110 | + (or (str/ends-with? lower-path ".clj") |
| 111 | + (str/ends-with? lower-path ".cljs") |
| 112 | + (str/ends-with? lower-path ".cljc") |
| 113 | + (str/ends-with? lower-path ".bb") |
| 114 | + (str/ends-with? lower-path ".lpy") |
| 115 | + (str/ends-with? lower-path ".edn") |
| 116 | + (babashka-shebang? file-path))))) |
118 | 117 |
|
119 | 118 | (defn extract-paths-from-bash-command |
120 | 119 | "Extract file/directory paths from a bash command string. |
|
0 commit comments