fork/gdu
git clone https://git.julia.blue/fork/gdu
d672bf4
subvolume
1package webui 2 3import ( 4"fmt" 5"os/exec" 6"runtime" 7"strings" 8) 9 10// browserCommand builds the command used to open url. When cmd is non-empty it 11// is treated as a launcher command line (the URL is appended as the final 12// argument); otherwise the platform default handler for goos is used. 13func browserCommand (goos ,url ,cmd string ) (name string ,args []string ,err error ) { 14if cmd != "" { 15fields := strings .Fields (cmd ) 16if len (fields )== 0 { 17return "" ,nil ,fmt .Errorf ("empty browser command" ) 18 } 19return fields [0 ],append (fields [1 :],url ),nil 20 } 21 22switch goos { 23case "darwin" : 24return "open" , []string {url },nil 25case "windows" : 26return "rundll32" , []string {"url.dll,FileProtocolHandler" ,url },nil 27default : 28return "xdg-open" , []string {url },nil 29 } 30} 31 32// openBrowser opens url in a browser using the configured or default launcher. 33func openBrowser (url ,cmd string )error { 34name ,args ,err := browserCommand (runtime .GOOS ,url ,cmd ) 35if err != nil { 36return err 37 } 38return exec .Command (name ,args ... ).Start () 39}