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

Loading…
Cancel
Save