Skip to content

Instantly share code, notes, and snippets.

@jasperla
Created December 13, 2011 22:22
Show Gist options
  • Save jasperla/1474185 to your computer and use it in GitHub Desktop.
Save jasperla/1474185 to your computer and use it in GitHub Desktop.
diff --git a/src/clj/clojure/java/browse.clj b/src/clj/clojure/java/browse.clj
index d6f710b..3924245 100644
--- a/src/clj/clojure/java/browse.clj
+++ b/src/clj/clojure/java/browse.clj
@@ -10,14 +10,29 @@
^{:author "Christophe Grand",
:doc "Start a web browser from Clojure"}
clojure.java.browse
+ (:use [clojure.string :only (split)])
(:require [clojure.java.shell :as sh])
- (:import (java.net URI)))
+ (:import (java.net URI)
+ (java.io File)))
-(defn- macosx? []
+(defn- macosx?
+ "Determine if we're currently running on Mac OS X."
+ []
(-> "os.name" System/getProperty .toLowerCase
- (.startsWith "mac os x")))
+ (.startsWith "mac os x")))
-(def ^:dynamic *open-url-script* (when (macosx?) "/usr/bin/open"))
+(defn- exec-file
+ [x]
+ (and (.exists (File. x)) x))
+
+(defn- get-xdg-open
+ "Determine the path to freedesktop.org's xdg-open, which is used on various
+ platforms such as GNU/Linux and BSD to open URIs"
+ []
+ (some exec-file (map (partial format "%s/xdg-open")
+ (-> (System/getenv) (get "PATH") (split #":")))))
+
+(def ^:dynamic *open-url-script* (if (macosx?) "/usr/bin/open" (get-xdg-open)))
(defn- open-url-in-browser
"Opens url (a string) in the default system web browser. May not
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment