You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

130 lines
4.4 KiB

2 years ago
;; fennel-ls doesn't support arbitrary allowed globals, so
;; unwrap `hs` here to localize it to just one place
(local {: application
: dialog
: eventtap
: execute
: fs
: hotkey
2 years ago
: ipc
: loadSpoon
2 years ago
: logger
: notify
: pasteboard
: uielement
: window} hs)
(local log (logger.new :log :info))
(set logger.defaultLogLevel :info)
2 years ago
(local {: mash : smash : modal-bind} (require :hotkey))
;; debugging
2 years ago
; (hotkey.bind mash "d" #(dialog.blockAlert "message" "text" "one" "two"))
;; defeat paste blocking
2 years ago
(hotkey.bind [:cmd :alt] :v #(eventtap.keyStrokes (pasteboard.getContents)))
(fn run [...]
(accumulate [last nil _ cmd (ipairs [...])]
(execute cmd)))
(fn with-selection [cb]
(let [app (application.frontmostApplication)
prev-pasteboard (pasteboard.getContents)
e (uielement.focusedElement)
text (if e (e:selectedText)
(do
2 years ago
(eventtap.keyStroke [:cmd] :c)
(pasteboard.getContents)))
content (cb text prev-pasteboard)]
(pasteboard.setContents content)
(app:setFrontmost)
2 years ago
(eventtap.keyStroke [:cmd] :v)
(pasteboard.setContents prev-pasteboard)))
(fn chomp [s]
(if (= (s:sub -1) "\n")
(s:sub 1 -2)
s))
2 years ago
(hotkey.bind mash :e
#(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)
(.. "/opt/homebrew/bin/neovide --nofork "
file)
(.. "pbcopy < " file) (.. "rm " file))
(pasteboard.getContents)))))
2 years ago
(hotkey.bind mash :t #(execute "/opt/homebrew/bin/alacritty msg create-window"))
2 years ago
(modal-bind mash "," nil
[[mash
:l
nil
(fn []
(with-selection #(.. "[" $1 "]" "(" $2 ")")))]])
2 years ago
2 years ago
;;; Elgato Key Light Air
2 years ago
;; Run `package.loaded["key-light-air"]["find-hostname"]()`
;; to find the hostname of the Key Light Air
(require :key-light-air)
;;; Spoons
2 years ago
(loadSpoon :SpoonInstall)
2 years ago
(local {:SpoonInstall Install} spoon)
(set Install.use_syncinstall true)
;; fnlfmt: skip
(local hotkeys {:up [mash :k]
:left [mash :h]
:down [mash :j]
:right [mash :l]
:fullscreen [mash :m]
:nextscreen [mash :n]})
(set window.animationDuration 0.0)
(Install:andUse :MiroWindowsManager {:config {:GRID {:w 6 :h 4}} : hotkeys})
(Install:andUse :WindowGrid {:config {:gridGeometries [[:6x4]]}
:hotkeys {:show_grid [mash :g]}
:start true})
(let [browsers {:arc :company.thebrowser.Browser
:firefox-dev :org.mozilla.firefoxdeveloperedition
:firefox :org.mozilla.firefox
:safari :com.apple.Safari
:zoom :us.zoom.xos}
url_patterns [["^https://(.*%.?)zoom.us/j/%d+" browsers.zoom]
["^https://(.*%.?)discnw.org/?" browsers.safari]
["^https://(.*%.?)squareupmessaging.com/?" browsers.safari]
["^https://(.*%.?)bulletin.com/?" browsers.safari]
["^https://(.*%.?)store.apple.com/?" browsers.safari]
2 years ago
["^https://(.*%.?)goodluckbread.com/?" browsers.safari]
["^https://community.glowforge.com/?" browsers.arc]]
url_redir_decoders [[:sci-hub
"^https://doi.org/(.*)"
"https://sci-hub.st/%1"]]]
(Install:andUse :URLDispatcher {:config {: url_patterns
: url_redir_decoders
:default_handler browsers.firefox-dev}
:start true}))
2 years ago
2 years ago
(Install:andUse :ReloadConfiguration {:start true})
;; Local overrides
2 years ago
(when (fs.attributes :local.fnl)
2 years ago
(require :local))
2 years ago
(let [n (notify.new {:title :Hammerspoon
:informativeText "Config loaded"
:withdrawAfter 2})]
(n:send))