Alpha Chen 11 months ago
parent da4a9ca18f
commit ba7d565faa
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -23,49 +23,25 @@
; (set logger.defaultLogLevel :info) ; (set logger.defaultLogLevel :info)
(local {: mash : smash : modal-bind} (require :hotkey)) (local {: mash : smash : modal-bind} (require :hotkey))
(local {: chomp : paste : replace-selection : run} (require :utils))
;; debugging ;; debugging
; (hotkey.bind mash "d" #(dialog.blockAlert "message" "text" "one" "two")) ; (hotkey.bind mash "d" #(dialog.blockAlert "message" "text" "one" "two"))
;; defeat paste blocking ;; ⌘⌥V - defeat paste blocking
(hotkey.bind [:cmd :alt] :v #(eventtap.keyStrokes (pasteboard.getContents))) (hotkey.bind [:cmd :alt] :v #(eventtap.keyStrokes (pasteboard.getContents)))
(fn run [...] ;; ⌘⌥⌃E - edit selected text in neovide, inspired by quickcursor (hence the temporary filenme)
(accumulate [last nil _ cmd (ipairs [...])] (let [editor "/opt/homebrew/bin/neovide --nofork"
(execute cmd))) cb (fn [text]
(let [home (os.getenv :HOME)
(fn with-selection [cb] date (chomp (run "date -Iseconds -u"))
(let [app (application.frontmostApplication) file (.. home :/.quickcursor. date)]
prev-pasteboard (pasteboard.getContents) (pasteboard.setContents text)
e (uielement.focusedElement) (run (.. "pbpaste > " file) (.. editor " " file)
text (if e (e:selectedText) (.. "pbcopy < " file) (.. "rm " file))
(do (pasteboard.getContents)))]
(eventtap.keyStroke [:cmd] :c) (hotkey.bind mash :e #(replace-selection cb)))
(pasteboard.getContents)))
content (cb text prev-pasteboard)]
(pasteboard.setContents content)
(app:setFrontmost)
(eventtap.keyStroke [:cmd] :v)
(pasteboard.setContents prev-pasteboard)))
(fn chomp [s]
(if (= (s:sub -1) "\n")
(s:sub 1 -2)
s))
;; mash-e: edit selected text in neovide, inspired by quickcursor (hence
;; the temporary filenme)
(hotkey.bind mash :e
(let [editor "/opt/homebrew/bin/neovide --nofork"]
#(with-selection (fn [text]
(let [home (os.getenv :HOME)
date (chomp (run "date -Iseconds -u"))
file (.. home :/.quickcursor. date)]
(pasteboard.setContents text)
(run (.. "pbpaste > " file)
(.. editor " " file)
(.. "pbcopy < " file) (.. "rm " file))
(pasteboard.getContents))))))
;; mash-, modal hotkeys ;; mash-, modal hotkeys
(modal-bind mash "," nil (modal-bind mash "," nil
@ -123,13 +99,13 @@
;; By default, URLDispatcher focuses the application before opening the URL, but ;; By default, URLDispatcher focuses the application before opening the URL, but
;; this interacts poorly with Arc since then we can be in the wrong space when ;; this interacts poorly with Arc since then we can be in the wrong space when
;; the URL is opened in Little Arc. ;; the URL is opened in Little Arc.
(let [handlers {:arc #(urlevent.openURLWithBundle $1 (let [open-in-arc #(urlevent.openURLWithBundle $1 :company.thebrowser.Browser)
:company.thebrowser.Browser) handlers {:arc open-in-arc
:firefox-dev :org.mozilla.firefoxdeveloperedition :firefox-dev :org.mozilla.firefoxdeveloperedition
:firefox :org.mozilla.firefox :firefox :org.mozilla.firefox
:safari :com.apple.Safari :safari :com.apple.Safari
:zoom :us.zoom.xos} :zoom :us.zoom.xos}
url_patterns [["^https://(.*%.?)zoom.us/j/%d+" handlers.zoom] url-patterns [["^https://(.*%.?)zoom.us/j/%d+" handlers.zoom]
["^https://(.*%.?)discnw.org/?" handlers.safari] ["^https://(.*%.?)discnw.org/?" handlers.safari]
["^https://(.*%.?)squareupmessaging.com/?" handlers.safari] ["^https://(.*%.?)squareupmessaging.com/?" handlers.safari]
["^https://(.*%.?)bulletin.com/?" handlers.safari] ["^https://(.*%.?)bulletin.com/?" handlers.safari]
@ -137,15 +113,15 @@
["^https://(.*%.?)goodluckbread.com/?" handlers.safari] ["^https://(.*%.?)goodluckbread.com/?" handlers.safari]
["^https://community.glowforge.com/?" handlers.arc] ["^https://community.glowforge.com/?" handlers.arc]
["^https://accounts.google.com/?" handlers.arc]] ["^https://accounts.google.com/?" handlers.arc]]
url_redir_decoders [[:sci-hub url-redir-decoders [[:sci-hub
"^https://doi.org/(.*)" "^https://doi.org/(.*)"
"https://sci-hub.st/%1"] "https://sci-hub.st/%1"]
[:twitter [:twitter
"^https://twitter.com/(.*)" "^https://twitter.com/(.*)"
"https://nitter.net/%1"] "https://nitter.net/%1"]
[:x "^https://x.com/(.*)" "https://nitter.net/%1"]]] [:x "^https://x.com/(.*)" "https://nitter.net/%1"]]]
(Install:andUse :URLDispatcher {:config {: url_patterns (Install:andUse :URLDispatcher {:config {:url_patterns url-patterns
: url_redir_decoders :url_redir_decoders url-redir-decoders
:default_handler handlers.arc :default_handler handlers.arc
:set_system_handler true} :set_system_handler true}
:start true})) :start true}))
@ -156,8 +132,7 @@
(when (fs.attributes :local.fnl) (when (fs.attributes :local.fnl)
(require :local)) (require :local))
(let [n (notify.new {:title :Hammerspoon (: (notify.new {:title :Hammerspoon
:informativeText "Config loaded" :informativeText "Config loaded"
:withdrawAfter 2})] :withdrawAfter 2}) :send)
(n:send))

Loading…
Cancel
Save