1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Added HTTP/HTTPS handling in OpenFile() function in wtf/utils.go to manage proper URL openings

This commit is contained in:
Johan Denoyer 2019-01-18 16:33:27 +01:00
parent 1d888118c5
commit 5adfbfb066

View File

@ -7,6 +7,7 @@ import (
"regexp" "regexp"
"strings" "strings"
//"sync" //"sync"
"runtime"
"github.com/rivo/tview" "github.com/rivo/tview"
) )
@ -95,11 +96,22 @@ func NamesFromEmails(emails []string) []string {
// OpenFile opens the file defined in `path` via the operating system // OpenFile opens the file defined in `path` via the operating system
func OpenFile(path string) { func OpenFile(path string) {
filePath, _ := ExpandHomeDir(path) if (strings.HasPrefix(path,"http://"))||(strings.HasPrefix(path,"https://")) {
openFileUtil := Config.UString("wtf.openFileUtil", "open") switch runtime.GOOS {
cmd := exec.Command(openFileUtil, filePath) case "linux":
exec.Command("xdg-open", path).Start()
ExecuteCommand(cmd) case "windows":
exec.Command("rundll32", "url.dll,FileProtocolHandler", path).Start()
case "darwin":
exec.Command("open", path).Start()
default:
}
}else {
filePath, _ := ExpandHomeDir(path)
openFileUtil := Config.UString("wtf.openFileUtil", "open")
cmd := exec.Command(openFileUtil, filePath)
ExecuteCommand(cmd)
}
} }
// PadRow returns a padding for a row to make it the full width of the containing widget. // PadRow returns a padding for a row to make it the full width of the containing widget.