From 5ba4056560828850224dae0664ac4306e09a94fa Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Sun, 19 Jul 2020 08:26:20 -0700 Subject: [PATCH] [hammerspoon] follow redirects when handling URLs --- .hammerspoon/init.fnl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/.hammerspoon/init.fnl b/.hammerspoon/init.fnl index 8a4ba3e..c41011d 100644 --- a/.hammerspoon/init.fnl +++ b/.hammerspoon/init.fnl @@ -1,3 +1,5 @@ +(local log (hs.logger.new "log" "info")) + (let [mash [:cmd :alt :ctrl] smash [:cmd :alt :ctrl :shift] wm {:left hs.layout.left50 @@ -17,7 +19,14 @@ ;; defeat paste blocking (hs.hotkey.bind [:cmd :alt] "v" (fn [] (hs.eventtap.keyStrokes (hs.pasteboard.getContents))))) -(set hs.urlevent.httpCallback (fn [scheme host params fullURL] - (if (string.find fullURL "^https?://.*[.]zoom.us/j/%d+") - (hs.urlevent.openURLWithBundle fullURL "us.zoom.xos") - (hs.urlevent.openURLWithBundle fullURL "org.mozilla.firefoxdeveloperedition")))) +(set hs.logger.defaultLogLevel "info") + +(set hs.urlevent.httpCallback + (fn [scheme host params fullURL] + (let [command (.. "curl -Ls -o /dev/null -w %{url_effective} " fullURL) + handle (io.popen command) + url (handle:read "*a")] + (if (string.find url "^https?://.*[.]zoom.us/j/%d+") + (hs.urlevent.openURLWithBundle fullURL "us.zoom.xos") + (hs.urlevent.openURLWithBundle fullURL "org.mozilla.firefoxdeveloperedition"))))) +