Use WSL2 detection to pick browser
This commit is contained in:
parent
2071c72a05
commit
6d111b2458
1 changed files with 24 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package browser
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
|
|
@ -30,7 +31,11 @@ func ForOS(goos, url string) *exec.Cmd {
|
|||
r := strings.NewReplacer("&", "^&")
|
||||
args = append(args, "/c", "start", r.Replace(url))
|
||||
default:
|
||||
exe = "xdg-open"
|
||||
if inWsl() {
|
||||
exe = "wslview"
|
||||
} else {
|
||||
exe = "xdg-open"
|
||||
}
|
||||
args = append(args, url)
|
||||
}
|
||||
|
||||
|
|
@ -51,3 +56,21 @@ func FromLauncher(launcher, url string) (*exec.Cmd, error) {
|
|||
cmd.Stderr = os.Stderr
|
||||
return cmd, nil
|
||||
}
|
||||
|
||||
// Determine if gh is running inside of WSL2
|
||||
func inWsl() bool {
|
||||
file, err := os.Open("/proc/sys/kernel/osrelease")
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
scanner.Scan() // Read single line
|
||||
if err := scanner.Err(); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
os := scanner.Text()
|
||||
return strings.Contains(os, "microsoft-WSL2")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue