diff --git a/README.md b/README.md index b6e8458..cb1fe48 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Currently state of platform support is: * macos => default, as well as browsers listed under [Browser](enum.Browser.html) * windows => default browser only -* linux => default browser only (uses $BROWSER env var, failing back to xdg-open, gvfs-open, gnome-open, whichever works first) +* linux/*bsd => default browser only (uses $BROWSER env var, failing back to xdg-open, gvfs-open, gnome-open, whichever works first) * android => not supported right now * ios => not supported right now diff --git a/src/lib.rs b/src/lib.rs index 49eb569..23d7f79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,7 +6,7 @@ //! //! * macos => default, as well as browsers listed under [Browser](enum.Browser.html) //! * windows => default browser only -//! * linux => default browser only (uses $BROWSER env var, failing back to xdg-open, gvfs-open and +//! * linux or *bsd => default browser only (uses $BROWSER env var, failing back to xdg-open, gvfs-open and //! gnome-open, in that order) //! * android => not supported right now //! * ios => not supported right now @@ -235,17 +235,22 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result { } } -/// Deal with opening of browsers on Linux - currently supports only the default browser +/// Deal with opening of browsers on Linux and *BSD - currently supports only the default browser /// /// The mechanism of opening the default browser is as follows: /// 1. Attempt to use $BROWSER env var if available /// 2. Attempt to open the url via xdg-open, gvfs-open, gnome-open, respectively, whichever works /// first -#[cfg(target_os = "linux")] +#[cfg(any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" +))] #[inline] fn open_browser_internal(browser: Browser, url: &str) -> Result { match browser { - Browser::Default => open_on_linux_using_browser_env(url) + Browser::Default => open_on_unix_using_browser_env(url) .or_else(|_| -> Result { Command::new("xdg-open").arg(url).output() }) .or_else(|_| -> Result { Command::new("gvfs-open").arg(url).output() }) .or_else(|_| -> Result { Command::new("gnome-open").arg(url).output() }), @@ -255,10 +260,13 @@ fn open_browser_internal(browser: Browser, url: &str) -> Result { )), } } - -/// Open on Linux using the $BROWSER env var -#[cfg(target_os = "linux")] -fn open_on_linux_using_browser_env(url: &str) -> Result { +#[cfg(any( + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" +))] +fn open_on_unix_using_browser_env(url: &str) -> Result { let browsers = ::std::env::var("BROWSER") .map_err(|_| -> Error { Error::new(ErrorKind::NotFound, "BROWSER env not set") })?; for browser in browsers.split(':') { @@ -290,8 +298,15 @@ fn open_on_linux_using_browser_env(url: &str) -> Result { )) } -#[cfg(not(any(target_os = "windows", target_os = "macos", target_os = "linux")))] -compile_error!("Only Windows, Mac OS and Linux are currently supported"); +#[cfg(not(any( + target_os = "windows", + target_os = "macos", + target_os = "linux", + target_os = "freebsd", + target_os = "netbsd", + target_os = "openbsd" +)))] +compile_error!("Only Windows, Mac OS, Linux and *BSD are currently supported"); #[test] fn test_open_default() {