Skip to content

Commit 466fe2b

Browse files
authored
Merge pull request #51 from thanhkaiba/master
Update command "open" for specific OS
2 parents 8e4e8ca + bb3848d commit 466fe2b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

cmd/clone.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,35 @@ func cloneSite(ctx context.Context, args []string) error {
7474

7575
}
7676
if Serve {
77-
cmd := exec.Command("open", "http://localhost:5000")
77+
cmd := open("http://localhost:5000")
7878
if err := cmd.Start(); err != nil {
7979
return fmt.Errorf("%v: %w", cmd.Args, err)
8080
}
8181
return server.Serve(firstProject)
8282
} else if Open {
8383
// automatically open project
84-
cmd := exec.Command("open", firstProject+"/index.html")
84+
cmd := open("open", firstProject+"/index.html")
8585
if err := cmd.Start(); err != nil {
8686
return fmt.Errorf("%v: %w", cmd.Args, err)
8787
}
8888
}
8989
return nil
9090
}
91+
92+
// open opens the specified URL in the default browser of the user.
93+
func open(url string) *exec.Cmd {
94+
var cmd string
95+
var args []string
96+
97+
switch runtime.GOOS {
98+
case "windows":
99+
cmd = "cmd"
100+
args = []string{"/c", "start"}
101+
case "darwin":
102+
cmd = "open"
103+
default: // "linux", "freebsd", "openbsd", "netbsd"
104+
cmd = "xdg-open"
105+
}
106+
args = append(args, url)
107+
return exec.Command(cmd, args...)
108+
}

0 commit comments

Comments
 (0)