diff --git a/.hammerspoon/init.fnl b/.hammerspoon/init.fnl index afe6c72..03d11cf 100644 --- a/.hammerspoon/init.fnl +++ b/.hammerspoon/init.fnl @@ -52,29 +52,30 @@ ;; mdls -name kMDItemCFBundleIdentifier -r SomeApp.app ;; fnlfmt: skip -(local matchers {".*[.]zoom.us/j/%d+" :us.zoom.xos - ; ".*[.]webex.com/" :com.webex.meetingmanager - ".*[.]discnw.org/" :com.apple.Safari - :squareup.com/ :com.apple.Safari}) - -(fn bundleIDForURL [url] - (var bundleID nil) - (each [key value (pairs matchers) :until bundleID] - (if (string.find url (.. "^https://" key)) - (set bundleID value))) - (or bundleID :org.mozilla.firefoxdeveloperedition)) +(local bundle-ids {:firefox :org.mozilla.firefoxdeveloperedition + :safari :com.apple.Safari + :zoom :us.zoom.xos}) + +(fn handle [url orig-url] + (let [open-with (fn [app] + (partial #(hs.urlevent.openURLWithBundle $2 $1) + (. bundle-ids app))) + open-url #((open-with $1) url)] + (if (string.find url "^https://.*[.]zoom.us/j/%d+") (open-url :zoom) + (string.find url "^https://.*[.]discnw.org/") (open-url :safari) + (string.find url "^https://squareup.com/") (open-url :safari) + (string.find orig-url "^https://doi.org/") + ((open-with :firefox) (.. "https://sci-hub.st/" orig-url)) + (open-url :firefox)))) (set hs.urlevent.httpCallback (fn [scheme host params url] (let [run #(: (io.popen (.. $1 " \"" $2 "\"")) :read :*a) de-utm (partial run "~/.dotfiles/bin/de-utm") redirect (partial run "curl -Ls -o /dev/null -w %{url_effective}") - final-url (->> url - (de-utm) - (redirect) - (de-utm)) - bundleID (bundleIDForURL final-url)] - (hs.urlevent.openURLWithBundle final-url bundleID)))) + orig-url (de-utm url) + redirected (de-utm (redirect orig-url))] + (handle redirected orig-url)))) ;;; Spoons @@ -97,3 +98,4 @@ (: (hs.notify.new {:title :Hammerspoon :informativeText "Config loaded" :withdrawAfter 2}) :send) + diff --git a/macos/Alfred.alfredpreferences/preferences/features/websearch/prefs.plist b/macos/Alfred.alfredpreferences/preferences/features/websearch/prefs.plist index 74bca44..7c384e2 100644 --- a/macos/Alfred.alfredpreferences/preferences/features/websearch/prefs.plist +++ b/macos/Alfred.alfredpreferences/preferences/features/websearch/prefs.plist @@ -19,19 +19,6 @@ utf8 - 44474AB2-A23A-4D3C-AB64-0DFE164ED23A - - enabled - - keyword - sh - text - Open '{query}' in Sci-Hub - url - https://sci-hub.st/{query} - utf8 - - 491B807D-42B3-4CB4-861F-2ADF20727F53 enabled diff --git a/macos/Alfred.alfredpreferences/preferences/features/websearch/youtube/prefs.plist b/macos/Alfred.alfredpreferences/preferences/features/websearch/youtube/prefs.plist new file mode 100644 index 0000000..79dfbaa --- /dev/null +++ b/macos/Alfred.alfredpreferences/preferences/features/websearch/youtube/prefs.plist @@ -0,0 +1,8 @@ + + + + + keyword + yt + + diff --git a/macos/Alfred.alfredpreferences/resources/features.websearch.custom.44474AB2-A23A-4D3C-AB64-0DFE164ED23A.png b/macos/Alfred.alfredpreferences/resources/features.websearch.custom.44474AB2-A23A-4D3C-AB64-0DFE164ED23A.png deleted file mode 100644 index 75aba52..0000000 Binary files a/macos/Alfred.alfredpreferences/resources/features.websearch.custom.44474AB2-A23A-4D3C-AB64-0DFE164ED23A.png and /dev/null differ diff --git a/macos/Alfred.alfredpreferences/workflows/user.workflow.C2C2E221-9537-4F06-B465-99770399BBD4/icon.png b/macos/Alfred.alfredpreferences/workflows/user.workflow.C2C2E221-9537-4F06-B465-99770399BBD4/icon.png new file mode 100644 index 0000000..0a63e73 Binary files /dev/null and b/macos/Alfred.alfredpreferences/workflows/user.workflow.C2C2E221-9537-4F06-B465-99770399BBD4/icon.png differ diff --git a/macos/Alfred.alfredpreferences/workflows/user.workflow.C2C2E221-9537-4F06-B465-99770399BBD4/info.plist b/macos/Alfred.alfredpreferences/workflows/user.workflow.C2C2E221-9537-4F06-B465-99770399BBD4/info.plist new file mode 100644 index 0000000..09095d4 --- /dev/null +++ b/macos/Alfred.alfredpreferences/workflows/user.workflow.C2C2E221-9537-4F06-B465-99770399BBD4/info.plist @@ -0,0 +1,177 @@ + + + + + bundleid + dev.kejadlen.sci-hub + connections + + 2F37680A-B350-467A-BD23-806AEC9F3004 + + + destinationuid + F526679F-2346-4831-B920-A085F4E9B7E0 + modifiers + 0 + modifiersubtext + + vitoclose + + + + 99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC + + + destinationuid + 2F37680A-B350-467A-BD23-806AEC9F3004 + modifiers + 0 + modifiersubtext + + vitoclose + + + + F526679F-2346-4831-B920-A085F4E9B7E0 + + + destinationuid + E803BE34-15CD-42A3-B13A-59C2C773ECA6 + modifiers + 0 + modifiersubtext + + vitoclose + + + + + createdby + Alpha Chen + description + Open URL in Sci-Hub + disabled + + name + Sci-Hub + objects + + + config + + browser + + skipqueryencode + + skipvarencode + + spaces + + url + https://sci-hub.st/{query} + + type + alfred.workflow.action.openurl + uid + E803BE34-15CD-42A3-B13A-59C2C773ECA6 + version + 1 + + + config + + argumenttype + 1 + keyword + sh + subtext + + text + Open in Sci-Hub + withspace + + + type + alfred.workflow.input.keyword + uid + 99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC + version + 1 + + + config + + matchmode + 2 + matchstring + + replacestring + {var:clipboard} + + type + alfred.workflow.utility.replace + uid + F526679F-2346-4831-B920-A085F4E9B7E0 + version + 2 + + + config + + argument + {query} + passthroughargument + + variables + + clipboard + {clipboard} + + + type + alfred.workflow.utility.argument + uid + 2F37680A-B350-467A-BD23-806AEC9F3004 + version + 1 + + + readme + + uidata + + 2F37680A-B350-467A-BD23-806AEC9F3004 + + xpos + 285 + ypos + 90 + + 99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC + + xpos + 55 + ypos + 60 + + E803BE34-15CD-42A3-B13A-59C2C773ECA6 + + xpos + 585 + ypos + 60 + + F526679F-2346-4831-B920-A085F4E9B7E0 + + xpos + 435 + ypos + 90 + + + userconfigurationconfig + + webaddress + + +