Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(login): use $BROWSER environment variable when set to open browser window #34904

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
16 changes: 16 additions & 0 deletions internal/command/webbrowser/native.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
package webbrowser

import (
"context"
"fmt"
"os"
"os/exec"
"time"

"github.com/pkg/browser"
)

Expand All @@ -17,5 +23,15 @@ func NewNativeLauncher() Launcher {
type nativeLauncher struct{}

func (l nativeLauncher) OpenURL(url string) error {
browserEnv := os.Getenv("BROWSER")
if browserEnv != "" {
browserSh := fmt.Sprintf("%s '%s'", browserEnv, url)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cmd := exec.CommandContext(ctx, "sh", "-c", browserSh)
_, err := cmd.CombinedOutput()
return err
}

return browser.OpenURL(url)
}