Skip to content

Commit

Permalink
Open URLs stored in the Location field
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kristjan committed Oct 13, 2020
1 parent cd3271d commit 8c04508
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions cmd_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"os"
"os/exec"
"regexp"
"time"

aw "github.com/deanishe/awgo"
Expand Down Expand Up @@ -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
}
}
}

Expand Down

0 comments on commit 8c04508

Please sign in to comment.