github.com/mhlo/force@v0.22.28-0.20150915022417-6d05ecfb0b47/open.go (about)

     1  package main
     2  
     3  // taken from https://bitbucket.org/tebeka/go-wise/src/tip/desktop.go
     4  
     5  import (
     6  	"fmt"
     7  	"os/exec"
     8  	"runtime"
     9  	"strings"
    10  )
    11  
    12  var openCommands = map[string][]string{
    13  	"windows": []string{"cmd", "/c", "start"},
    14  	"darwin":  []string{"open"},
    15  	"linux":   []string{"xdg-open"},
    16  }
    17  
    18  func Open(uri string) error {
    19  	run, ok := openCommands[runtime.GOOS]
    20  	if !ok {
    21  		return fmt.Errorf("don't know how to open things on %s platform", runtime.GOOS)
    22  	}
    23  	if runtime.GOOS == "windows" {
    24  		uri = strings.Replace(uri, "&", "^&", -1)
    25  	}
    26  	run = append(run, uri)
    27  	cmd := exec.Command(run[0], run[1:]...)
    28  	return cmd.Start()
    29  }