|
82 | 82 |
|
83 | 83 | (validate-path path current-dir allowed-dirs))) |
84 | 84 |
|
85 | | -(defn clojure-file? |
86 | | - "Checks if a file path has a Clojure-related extension. |
87 | | - |
88 | | - Supported extensions: |
89 | | - - .clj (Clojure) |
90 | | - - .cljs (ClojureScript) |
91 | | - - .cljc (Clojure/ClojureScript shared) |
92 | | - - .bb (Babashka) |
93 | | - - .edn (Extensible Data Notation)" |
94 | | - [file-path] |
95 | | - (when file-path |
96 | | - (let [lower-path (str/lower-case file-path)] |
97 | | - (or (str/ends-with? lower-path ".clj") |
98 | | - (str/ends-with? lower-path ".cljs") |
99 | | - (str/ends-with? lower-path ".cljc") |
100 | | - (str/ends-with? lower-path ".bb") |
101 | | - (str/ends-with? lower-path ".lpy") |
102 | | - (str/ends-with? lower-path ".edn"))))) |
| 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 | + |
| 100 | + Supported extensions: |
| 101 | + - .clj (Clojure) |
| 102 | + - .cljs (ClojureScript) |
| 103 | + - .cljc (Clojure/ClojureScript shared) |
| 104 | + - .bb (Babashka) |
| 105 | + - .edn (Extensible Data Notation) |
| 106 | + - .lpy (Librepl) |
| 107 | + 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))))) |
103 | 118 |
|
104 | 119 | (defn extract-paths-from-bash-command |
105 | 120 | "Extract file/directory paths from a bash command string. |
|
0 commit comments