better modal bindings

pull/2/head
Alpha Chen 2 years ago
parent fab2e2e568
commit 742d754b87
No known key found for this signature in database

@ -0,0 +1,9 @@
(fn modal-bind [mods key message bindings]
(let [modal (hs.hotkey.modal.new mods key message)]
(tset modal :entered #(hs.timer.doAfter 0.5 #(modal:exit)))
; (tset modal :exited #(hs.alert :exited))
(each [_ [mods key message f] (ipairs bindings)]
(modal:bind mods key message #(do (f) (modal:exit))))))
{:mash [:cmd :alt :ctrl] :smash [:cmd :alt :ctrl :shift] : modal-bind}

@ -1,8 +1,7 @@
(local log (hs.logger.new :log :info)) (local log (hs.logger.new :log :info))
(set hs.logger.defaultLogLevel :info) (set hs.logger.defaultLogLevel :info)
(local mash [:cmd :alt :ctrl]) (local {: mash : smash : modal-bind} (require :hotkey))
(local smash [:cmd :alt :ctrl :shift])
(set hs.window.animationDuration 0.0) (set hs.window.animationDuration 0.0)
(hs.loadSpoon :MiroWindowsManager) (hs.loadSpoon :MiroWindowsManager)
@ -39,19 +38,36 @@
file (.. "~/.quickcursor." date)] file (.. "~/.quickcursor." date)]
(hs.pasteboard.setContents text) (hs.pasteboard.setContents text)
(hs.execute (.. "pbpaste > " file)) (hs.execute (.. "pbpaste > " file))
(hs.execute (.. "/opt/homebrew/bin/mvim --nofork " file)) (hs.execute (.. "/opt/homebrew/bin/neovide --nofork " file))
(hs.execute (.. "pbcopy < " file)) (hs.execute (.. "pbcopy < " file))
(app:setFrontmost) (app:setFrontmost)
(hs.eventtap.keyStroke [:cmd] :v) (hs.eventtap.keyStroke [:cmd] :v)
(hs.execute (.. "rm " file)) (hs.execute (.. "rm " file))
(hs.pasteboard.setContents prev-pasteboard))) (hs.pasteboard.setContents prev-pasteboard)))
(fn linkify []
(let [app (hs.application.frontmostApplication)
prev-pasteboard (hs.pasteboard.getContents)
e (hs.uielement.focusedElement)
text (if e (e:selectedText)
(do
(hs.eventtap.keyStroke [:cmd] :c)
(hs.pasteboard.getContents)))
link (.. "[" text "]" "(" prev-pasteboard ")")]
(hs.pasteboard.setContents link)
(app:setFrontmost)
(hs.eventtap.keyStroke [:cmd] :v)
(hs.pasteboard.setContents prev-pasteboard)))
(modal-bind mash "," "," [[mash :l :linkify linkify]])
;; https://stackoverflow.com/questions/39464668/how-to-get-bundle-id-of-mac-application ;; https://stackoverflow.com/questions/39464668/how-to-get-bundle-id-of-mac-application
;; osascript -e 'id of app "SomeApp"' ;; osascript -e 'id of app "SomeApp"'
;; mdls -name kMDItemCFBundleIdentifier -r SomeApp.app ;; mdls -name kMDItemCFBundleIdentifier -r SomeApp.app
;; fnlfmt: skip ;; fnlfmt: skip
(local bundle-ids {:firefox :org.mozilla.firefoxdeveloperedition (local bundle-ids {:firefox :org.mozilla.firefoxdeveloperedition
:firefox :org.mozilla.firefox
:safari :com.apple.Safari :safari :com.apple.Safari
:zoom :us.zoom.xos}) :zoom :us.zoom.xos})
@ -67,7 +83,7 @@
(string.find orig-url "^https://doi.org/") (string.find orig-url "^https://doi.org/")
((open-with :firefox) (.. "https://sci-hub.st/" orig-url)) ((open-with :firefox) (.. "https://sci-hub.st/" orig-url))
(string.find orig-url "^https://.*[.]usps.com/") (string.find orig-url "^https://.*[.]usps.com/")
((open-with :firefox) orig-url) (open-url :firefox)))) ((open-with :firefox) orig-url) (open-url :safari))))
(set hs.urlevent.httpCallback (set hs.urlevent.httpCallback
(fn [scheme host params url] (fn [scheme host params url]
@ -97,29 +113,26 @@
(accumulate [docked? false _ v (pairs (hs.usb.attachedDevices)) &until docked?] (accumulate [docked? false _ v (pairs (hs.usb.attachedDevices)) &until docked?]
(or docked? (= v.productName "CalDigit Thunderbolt 3 Audio")))) (or docked? (= v.productName "CalDigit Thunderbolt 3 Audio"))))
(local key-light-air-watcher (local key-light-air-watcher (let [{: watcher} hs.caffeinate]
(let [{: watcher} hs.caffeinate] (: (watcher.new #(when (docked?)
(watcher.new #(when (docked?) (match $1
(match $1 watcher.screensDidLock (update-key-light-air false)
watcher.screensDidLock (update-key-light-air false) watcher.screensDidSleep (update-key-light-air false)
watcher.screensDidSleep (update-key-light-air false) watcher.screensDidUnlock (update-key-light-air true)
watcher.screensDidUnlock (update-key-light-air true) watcher.screensDidWake (update-key-light-air true))))
watcher.screensDidWake (update-key-light-air true)))))) :start)))
(when (docked?) ; (local usb-watcher (: (hs.usb.watcher.new #(let [{: eventType : productName} $1]
(key-light-air-watcher:start)) ; (when (= productName
; "CalDigit Thunderbolt 3 Audio")
(local usb-watcher (: (hs.usb.watcher.new #(let [{: eventType : productName} $1] ; (match eventType
(when (= productName ; :added (do
"CalDigit Thunderbolt 3 Audio") ; (update-key-light-air true)
(match eventType ; (key-light-air-watcher:start))
:added (do ; :removed (do
(update-key-light-air true) ; (update-key-light-air false)
(key-light-air-watcher:start)) ; (key-light-air-watcher:stop))))))
:removed (do ; :start))
(update-key-light-air false)
(key-light-air-watcher:stop))))))
:start))
;;; Spoons ;;; Spoons

Loading…
Cancel
Save