From c4873ec8b0baebf46659843ab731df98edad7f5e Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Fri, 18 Nov 2022 18:50:07 -0800 Subject: [PATCH] hoist default handlers --- .hammerspoon/handle-urls.fnl | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.hammerspoon/handle-urls.fnl b/.hammerspoon/handle-urls.fnl index 632b4df..e23d542 100644 --- a/.hammerspoon/handle-urls.fnl +++ b/.hammerspoon/handle-urls.fnl @@ -28,6 +28,11 @@ (fn open-with [app] (partial open-url app)) +(local default-handlers + [["^https://.*%.?zoom.us/j/%d+" (open-with :zoom)] + ["^https://doi.org/" + #(open-with :default (.. "https://sci-hub.st/" $1))]]) + (fn url->handler [url] (accumulate [acc nil _ [pat handler] (ipairs handlers) &until acc] (if (url:find pat) #(handler url) nil))) @@ -37,12 +42,9 @@ (handler))) (fn setup [{:bundle-ids extra-bundle-ids :handlers extra-handlers}] - (let [default-handlers [["^https://.*%.?zoom.us/j/%d+" (open-with :zoom)] - ["^https://doi.org/" - #(open-url :default (.. "https://sci-hub.st/" $1))]]] - (each [k v (pairs (or extra-bundle-ids {}))] - (tset bundle-ids k v)) - (set handlers (hs.fnutils.concat extra-handlers default-handlers)))) + (each [k v (pairs (or extra-bundle-ids {}))] + (tset bundle-ids k v)) + (set handlers (hs.fnutils.concat extra-handlers default-handlers))) (fn start [] (set hs.urlevent.httpCallback