From 5adfbfb06686350b7e0169e2f5772bfb23140c53 Mon Sep 17 00:00:00 2001 From: Johan Denoyer Date: Fri, 18 Jan 2019 16:33:27 +0100 Subject: [PATCH] Added HTTP/HTTPS handling in OpenFile() function in wtf/utils.go to manage proper URL openings --- wtf/utils.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/wtf/utils.go b/wtf/utils.go index 2ee581ab..234788d6 100644 --- a/wtf/utils.go +++ b/wtf/utils.go @@ -7,6 +7,7 @@ import ( "regexp" "strings" //"sync" + "runtime" "github.com/rivo/tview" ) @@ -95,11 +96,22 @@ func NamesFromEmails(emails []string) []string { // OpenFile opens the file defined in `path` via the operating system func OpenFile(path string) { - filePath, _ := ExpandHomeDir(path) - openFileUtil := Config.UString("wtf.openFileUtil", "open") - cmd := exec.Command(openFileUtil, filePath) - - ExecuteCommand(cmd) + if (strings.HasPrefix(path,"http://"))||(strings.HasPrefix(path,"https://")) { + switch runtime.GOOS { + case "linux": + exec.Command("xdg-open", path).Start() + 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.