[#495] add clojure.java.browse/browse-url
This commit is contained in:
parent
665f7e0956
commit
633264096d
2 changed files with 28 additions and 1 deletions
25
src/babashka/impl/clojure/java/browse.clj
Normal file
25
src/babashka/impl/clojure/java/browse.clj
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
(ns babashka.impl.clojure.java.browse
|
||||
{:no-doc true}
|
||||
(:require [clojure.java.shell :refer [sh]]
|
||||
[clojure.string :as str]))
|
||||
|
||||
(def os
|
||||
(let [os-name (System/getProperty "os.name")
|
||||
os-name (str/lower-case os-name)]
|
||||
(cond (str/starts-with? os-name "mac os x")
|
||||
:mac
|
||||
(str/includes? os-name "linux")
|
||||
:linux
|
||||
(str/includes? os-name "win")
|
||||
:windows)))
|
||||
|
||||
(defn browse-url [url]
|
||||
(let [url (str url)]
|
||||
(case os
|
||||
:mac (sh "/usr/bin/open" url)
|
||||
:linux (sh "/usr/bin/xdg-open" url)
|
||||
:windows (sh "cmd" "/C" "start" url))))
|
||||
|
||||
(def browse-namespace
|
||||
{'browse-url browse-url})
|
||||
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
[babashka.impl.classes :as classes]
|
||||
[babashka.impl.classpath :as cp]
|
||||
[babashka.impl.clojure.core :as core :refer [core-extras]]
|
||||
[babashka.impl.clojure.java.browse :refer [browse-namespace]]
|
||||
[babashka.impl.clojure.java.io :refer [io-namespace]]
|
||||
[babashka.impl.clojure.java.shell :refer [shell-namespace]]
|
||||
[babashka.impl.clojure.main :as clojure-main :refer [demunge]]
|
||||
|
|
@ -367,7 +368,8 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that
|
|||
'babashka.curl curl-namespace
|
||||
'babashka.pods pods/pods-namespace
|
||||
'bencode.core bencode-namespace
|
||||
'flatland.ordered.map ordered-map-ns}
|
||||
'flatland.ordered.map ordered-map-ns
|
||||
'clojure.java.browse browse-namespace}
|
||||
features/xml? (assoc 'clojure.data.xml @(resolve 'babashka.impl.xml/xml-namespace))
|
||||
features/yaml? (assoc 'clj-yaml.core @(resolve 'babashka.impl.yaml/yaml-namespace))
|
||||
features/jdbc? (assoc 'next.jdbc @(resolve 'babashka.impl.jdbc/njdbc-namespace)
|
||||
|
|
|
|||
Loading…
Reference in a new issue