fix(browser): show message if $BROWSER isn't in $PATH (#1749)

This commit is contained in:
zacanger 2020-09-23 10:17:54 +00:00 committed by GitHub
parent 929e082c13
commit f17d9672f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View file

@ -9,9 +9,14 @@ import (
"github.com/google/shlex"
)
// BrowserEnv simply returns the $BROWSER envionment variable
func FromEnv() string {
return os.Getenv("BROWSER")
}
// Command produces an exec.Cmd respecting runtime.GOOS and $BROWSER environment variable
func Command(url string) (*exec.Cmd, error) {
launcher := os.Getenv("BROWSER")
launcher := FromEnv()
if launcher != "" {
return FromLauncher(launcher, url)
}

View file

@ -19,7 +19,14 @@ func OpenInBrowser(url string) error {
if err != nil {
return err
}
return run.PrepareCmd(browseCmd).Run()
err = run.PrepareCmd(browseCmd).Run()
if err != nil {
browserEnv := browser.FromEnv()
if browserEnv != "" {
return fmt.Errorf("%w\nNote: check your BROWSER environment variable", err)
}
}
return err
}
func RenderMarkdown(text string) (string, error) {