diff --git a/README.md b/README.md index bba642f..3a9dcb6 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Chrome is recommended. ```bash -go get go.coder.com/sshcode +GO111MODULE=off go get go.coder.com/sshcode ``` ## Usage diff --git a/main.go b/main.go index 447e4d1..1fb5039 100644 --- a/main.go +++ b/main.go @@ -97,11 +97,19 @@ chmod +x ~/bin/code-server func openBrowser(url string) { var openCmd *exec.Cmd if commandExists("google-chrome") { - openCmd = exec.Command("google-chrome", "--app="+url, "--disable-extensions", "--disable-plugins") + openCmd = exec.Command("google-chrome", fmtChromeOptions(url)...) + + } else if commandExists("chromium") { + openCmd = exec.Command("chromium", fmtChromeOptions(url)...) + + } else if commandExists("chromium-browser") { + openCmd = exec.Command("chromium-browser", fmtChromeOptions(url)...) + } else if commandExists("firefox") { openCmd = exec.Command("firefox", "--url="+url, "-safe-mode") + } else { - flog.Info("unable to find a browser to open: sshcode only supports firefox and chrome") + flog.Info("unable to find a browser to open: sshcode only supports firefox, chrome, and chromium") return } @@ -112,6 +120,10 @@ func openBrowser(url string) { } } +func fmtChromeOptions(url string) []string { + return []string{"--app=" + url, "--disable-extensions", "--disable-plugins"} +} + // Checks if a command exists locally. func commandExists(name string) bool { _, err := exec.LookPath(name) @@ -124,7 +136,6 @@ func scanAvailablePort() (string, error) { l, err := net.Listen("tcp", fmt.Sprintf(":%d", port)) if err != nil { // If we have an error the port is taken. - port++ continue } _ = l.Close()