Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Try to use `xdg-open` as a browser on Linux #2154

Closed
wants to merge 1 commit into from

3 participants

@mmalecki
Owner

xdg-open is a command similar to open - it tries to find a preferred
command to open a resource with. However, it isn't present on some
machines (depending on window manager/desktop environment), thus we have
to check for it's existance with which.

@mmalecki mmalecki Try to use `xdg-open` as a browser on Linux
`xdg-open` is a command similar to `open` - it tries to find a preferred
command to open a resource with. However, it isn't present on some
machines (depending on window manager/desktop environment), thus we have
to check for it's existance with `which`.
50ed364
@Ralt

Using an exception to get the right browser seems weird to me. Isn't there a better way?

@domenic
Collaborator

This has likely been fixed by the move to "opener", which uses xdg-open. If not a new approach can be taken, perhaps by opening an issue in the opener repo.

@domenic domenic closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 13, 2012
  1. @mmalecki

    Try to use `xdg-open` as a browser on Linux

    mmalecki authored
    `xdg-open` is a command similar to `open` - it tries to find a preferred
    command to open a resource with. However, it isn't present on some
    machines (depending on window manager/desktop environment), thus we have
    to check for it's existance with `which`.
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/utils/config-defs.js
View
14 lib/utils/config-defs.js
@@ -4,6 +4,7 @@
var path = require("path")
, url = require("url")
, Stream = require("stream").Stream
+ , whichSync = require("which").sync
, semver = require("semver")
, stableFamily = semver.parse(process.version)
, os = require("os")
@@ -95,6 +96,14 @@ Object.defineProperty(exports, "defaults", {get: function () {
}
}
+ var browser = process.platform === "darwin" ? "open"
+ : process.platform === "win32" ? "start" : null;
+
+ if (process.platform === "linux") {
+ try { browser = whichSync("xdg-open") }
+ catch (_) { browser = "google-chrome" }
+ }
+
return defaults =
{ "always-auth" : false
@@ -114,10 +123,7 @@ Object.defineProperty(exports, "defaults", {get: function () {
+ os.release() )
// are there others?
- , browser : process.platform === "darwin" ? "open"
- : process.platform === "win32" ? "start"
- : "google-chrome"
-
+ , browser : browser
, ca : // the npm CA certificate.
"-----BEGIN CERTIFICATE-----\n"+
"MIIChzCCAfACCQDauvz/KHp8ejANBgkqhkiG9w0BAQUFADCBhzELMAkGA1UEBhMC\n"+
Something went wrong with that request. Please try again.