From 8c0450853984abf25ac1f05da69641b3609d07b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20P=C3=A9tursson?= Date: Tue, 13 Oct 2020 14:10:58 -0700 Subject: [PATCH] Open URLs stored in the Location field Calendar events now often contain URLs to video meetings from Zoom, etc. Those are no use to look up on a map, so open them directly instead. --- cmd_events.go | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/cmd_events.go b/cmd_events.go index 68c0a99..1349e13 100644 --- a/cmd_events.go +++ b/cmd_events.go @@ -13,6 +13,7 @@ import ( "log" "os" "os/exec" + "regexp" "time" aw "github.com/deanishe/awgo" @@ -144,18 +145,30 @@ func doEvents() error { Var("action", "open") if e.Location != "" { - app := "Google Maps" - if opts.UseAppleMaps { - app = "Apple Maps" - } + re := regexp.MustCompile(`https:\/\/([\w\-])+\.{1}([a-zA-Z]{2,63})([\/\w-]*)*\/?\??([^#\n\r, ]*)?`) + url := re.FindString(e.Location) + + if url != "" { + it.NewModifier("cmd"). + Subtitle("Open "+url). + Arg(url). + Valid(true). + Icon(icon). + Var("action", "open") + } else { + app := "Google Maps" + if opts.UseAppleMaps { + app = "Apple Maps" + } - icon := ColouredIcon(iconMap, e.Colour) - it.NewModifier("cmd"). - Subtitle("Open in "+app). - Arg(mapURL(e.Location)). - Valid(true). - Icon(icon). - Var("CALENDAR_APP", "") // Don't open Maps URLs in CALENDAR_APP + icon := ColouredIcon(iconMap, e.Colour) + it.NewModifier("cmd"). + Subtitle("Open in "+app). + Arg(mapURL(e.Location)). + Valid(true). + Icon(icon). + Var("CALENDAR_APP", "") // Don't open Maps URLs in CALENDAR_APP + } } }