aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--browser.go11
-rw-r--r--browser_linux.go8
2 files changed, 13 insertions, 6 deletions
diff --git a/browser.go b/browser.go
index 4b922ee..bc312f5 100644
--- a/browser.go
+++ b/browser.go
@@ -7,11 +7,16 @@ import (
"fmt"
"io"
"io/ioutil"
+ "path/filepath"
)
// OpenFile opens new browser window for the file path.
func OpenFile(path string) error {
- return openBrowser(path)
+ path, err := filepath.Abs(path)
+ if err != nil {
+ return err
+ }
+ return OpenURL("file://" + path)
}
// OpenReader consumes the contents of r and presents the
@@ -28,9 +33,7 @@ func OpenReader(r io.Reader) error {
if err := f.Close(); err != nil {
return fmt.Errorf("browser: caching temporary file failed: %v", err)
}
-
- //defer os.Remove(f.Name())
- return openBrowser(f.Name())
+ return OpenFile(f.Name())
}
// OpenURL opens a new browser window pointing to url.
diff --git a/browser_linux.go b/browser_linux.go
index e9e9b8c..ccd1685 100644
--- a/browser_linux.go
+++ b/browser_linux.go
@@ -5,6 +5,10 @@ import (
)
func openBrowser(url string) error {
- cmd := exec.Command("xdg-open", url)
- return cmd.Run()
+ sensibleBrowser, err := exec.LookPath("sensible-browser")
+ if err != nil {
+ // sensible-browser not availble, try xdg-open
+ return exec.Command("xdg-open", url).Run()
+ }
+ return exec.Command(sensibleBrowser, url).Run()
}