sci-hub improvements to alfred and hammerspoon
diff --git a/.hammerspoon/init.fnl b/.hammerspoon/init.fnl
index afe6c726..03d11cf5 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 74bca447..7c384e23 100644
--- a/macos/Alfred.alfredpreferences/preferences/features/websearch/prefs.plist
+++ b/macos/Alfred.alfredpreferences/preferences/features/websearch/prefs.plist
@@ -19,19 +19,6 @@
<key>utf8</key>
<true/>
</dict>
- <key>44474AB2-A23A-4D3C-AB64-0DFE164ED23A</key>
- <dict>
- <key>enabled</key>
- <true/>
- <key>keyword</key>
- <string>sh</string>
- <key>text</key>
- <string>Open '{query}' in Sci-Hub</string>
- <key>url</key>
- <string>https://sci-hub.st/{query}</string>
- <key>utf8</key>
- <true/>
- </dict>
<key>491B807D-42B3-4CB4-861F-2ADF20727F53</key>
<dict>
<key>enabled</key>
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 00000000..79dfbaaa
--- /dev/null
+++ b/macos/Alfred.alfredpreferences/preferences/features/websearch/youtube/prefs.plist
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>keyword</key>
+ <string>yt</string>
+</dict>
+</plist>
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 75aba52a..00000000
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 00000000..0a63e739
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 00000000..09095d4b
--- /dev/null
+++ b/macos/Alfred.alfredpreferences/workflows/user.workflow.C2C2E221-9537-4F06-B465-99770399BBD4/info.plist
@@ -0,0 +1,177 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>bundleid</key>
+ <string>dev.kejadlen.sci-hub</string>
+ <key>connections</key>
+ <dict>
+ <key>2F37680A-B350-467A-BD23-806AEC9F3004</key>
+ <array>
+ <dict>
+ <key>destinationuid</key>
+ <string>F526679F-2346-4831-B920-A085F4E9B7E0</string>
+ <key>modifiers</key>
+ <integer>0</integer>
+ <key>modifiersubtext</key>
+ <string></string>
+ <key>vitoclose</key>
+ <false/>
+ </dict>
+ </array>
+ <key>99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC</key>
+ <array>
+ <dict>
+ <key>destinationuid</key>
+ <string>2F37680A-B350-467A-BD23-806AEC9F3004</string>
+ <key>modifiers</key>
+ <integer>0</integer>
+ <key>modifiersubtext</key>
+ <string></string>
+ <key>vitoclose</key>
+ <false/>
+ </dict>
+ </array>
+ <key>F526679F-2346-4831-B920-A085F4E9B7E0</key>
+ <array>
+ <dict>
+ <key>destinationuid</key>
+ <string>E803BE34-15CD-42A3-B13A-59C2C773ECA6</string>
+ <key>modifiers</key>
+ <integer>0</integer>
+ <key>modifiersubtext</key>
+ <string></string>
+ <key>vitoclose</key>
+ <false/>
+ </dict>
+ </array>
+ </dict>
+ <key>createdby</key>
+ <string>Alpha Chen</string>
+ <key>description</key>
+ <string>Open URL in Sci-Hub</string>
+ <key>disabled</key>
+ <false/>
+ <key>name</key>
+ <string>Sci-Hub</string>
+ <key>objects</key>
+ <array>
+ <dict>
+ <key>config</key>
+ <dict>
+ <key>browser</key>
+ <string></string>
+ <key>skipqueryencode</key>
+ <true/>
+ <key>skipvarencode</key>
+ <true/>
+ <key>spaces</key>
+ <string></string>
+ <key>url</key>
+ <string>https://sci-hub.st/{query}</string>
+ </dict>
+ <key>type</key>
+ <string>alfred.workflow.action.openurl</string>
+ <key>uid</key>
+ <string>E803BE34-15CD-42A3-B13A-59C2C773ECA6</string>
+ <key>version</key>
+ <integer>1</integer>
+ </dict>
+ <dict>
+ <key>config</key>
+ <dict>
+ <key>argumenttype</key>
+ <integer>1</integer>
+ <key>keyword</key>
+ <string>sh</string>
+ <key>subtext</key>
+ <string></string>
+ <key>text</key>
+ <string>Open in Sci-Hub</string>
+ <key>withspace</key>
+ <true/>
+ </dict>
+ <key>type</key>
+ <string>alfred.workflow.input.keyword</string>
+ <key>uid</key>
+ <string>99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC</string>
+ <key>version</key>
+ <integer>1</integer>
+ </dict>
+ <dict>
+ <key>config</key>
+ <dict>
+ <key>matchmode</key>
+ <integer>2</integer>
+ <key>matchstring</key>
+ <string></string>
+ <key>replacestring</key>
+ <string>{var:clipboard}</string>
+ </dict>
+ <key>type</key>
+ <string>alfred.workflow.utility.replace</string>
+ <key>uid</key>
+ <string>F526679F-2346-4831-B920-A085F4E9B7E0</string>
+ <key>version</key>
+ <integer>2</integer>
+ </dict>
+ <dict>
+ <key>config</key>
+ <dict>
+ <key>argument</key>
+ <string>{query}</string>
+ <key>passthroughargument</key>
+ <true/>
+ <key>variables</key>
+ <dict>
+ <key>clipboard</key>
+ <string>{clipboard}</string>
+ </dict>
+ </dict>
+ <key>type</key>
+ <string>alfred.workflow.utility.argument</string>
+ <key>uid</key>
+ <string>2F37680A-B350-467A-BD23-806AEC9F3004</string>
+ <key>version</key>
+ <integer>1</integer>
+ </dict>
+ </array>
+ <key>readme</key>
+ <string></string>
+ <key>uidata</key>
+ <dict>
+ <key>2F37680A-B350-467A-BD23-806AEC9F3004</key>
+ <dict>
+ <key>xpos</key>
+ <real>285</real>
+ <key>ypos</key>
+ <real>90</real>
+ </dict>
+ <key>99B99B9B-2CEE-4B07-85DC-40BE5C4B03DC</key>
+ <dict>
+ <key>xpos</key>
+ <real>55</real>
+ <key>ypos</key>
+ <real>60</real>
+ </dict>
+ <key>E803BE34-15CD-42A3-B13A-59C2C773ECA6</key>
+ <dict>
+ <key>xpos</key>
+ <real>585</real>
+ <key>ypos</key>
+ <real>60</real>
+ </dict>
+ <key>F526679F-2346-4831-B920-A085F4E9B7E0</key>
+ <dict>
+ <key>xpos</key>
+ <real>435</real>
+ <key>ypos</key>
+ <real>90</real>
+ </dict>
+ </dict>
+ <key>userconfigurationconfig</key>
+ <array/>
+ <key>webaddress</key>
+ <string></string>
+</dict>
+</plist>