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.

129 lines
5.1 KiB

2 years ago
;; fennel-ls doesn't support arbitrary allowed globals, so
;; unwrap `hs` here to localize it to just one place
5 months ago
(local {: eventtap
2 years ago
: fs
: hotkey
1 year ago
: loadSpoon
2 years ago
: logger
: notify
: pasteboard
1 year ago
: urlevent
2 years ago
: window} hs)
1 year ago
(local log (logger.new :init :info))
; (set logger.defaultLogLevel :info)
2 years ago
2 years ago
(local {: mash : smash : modal-bind} (require :hotkey))
1 year ago
(local {: chomp : paste : replace-selection : run} (require :utils))
5 months ago
;;; quitter
(let [{: start} (require :quitter-v2)]
(start))
;; debugging
5 months ago
; (hotkey.bind mash "d" #(hs.notify.show (: (hs.window.frontmostWindow) :title) "" ""))
1 year ago
;; ⌘⌥V - defeat paste blocking
2 years ago
(hotkey.bind [:cmd :alt] :v #(eventtap.keyStrokes (pasteboard.getContents)))
1 year ago
;; ⌘⌥⌃E - edit selected text in neovide, inspired by quickcursor (hence the temporary filenme)
5 months ago
(let [editor "/opt/homebrew/bin/neovide --no-fork"
1 year ago
cb (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)))]
(hotkey.bind mash :e #(replace-selection cb)))
;; mash-, modal hotkeys
2 years ago
(modal-bind mash "," nil
;; mash-, mash-l: create a markdown link using the selected
;; text as the title and pastboard contents as the link
2 years ago
[[mash
:l
nil
(fn []
(with-selection #(.. "[" $1 "]" "(" $2 ")")))]])
2 years ago
;; cmd-shift-c: copy current url
; (let [{: activated : deactivated} application.watcher
; firefox (hotkey.new [:cmd :shift] :c #(eventtap.keyStrokes :yy))
; safari-applescript "tell application \"Safari\" to get URL of front document"
; safari (hotkey.new [:cmd :shift] :c
; #(let [(_ obj _) (osascript.applescript safari-applescript)]
; (pasteboard.setContents obj)))
; per-app {"Firefox Developer Edition" firefox :Safari safari}
; update-app (fn [name event _app]
; (match [(. per-app name) event]
; [app-config activated] (app-config:enable)
; [app-config deactivated] (app-config:disable)))
; watcher (application.watcher.new update-app)]
; ;; hold onto watcher as a global so it doesn't get GC'ed
; (set _G.per-app-watcher (watcher:start)))
;;; Spoons
1 year ago
(loadSpoon :SpoonInstall)
2 years ago
(local {:SpoonInstall Install} spoon)
(set Install.use_syncinstall true)
(set window.animationDuration 0.0)
1 year ago
;; fnlfmt: skip
(let [hotkeys {:up [mash :k]
:left [mash :h]
:down [mash :j]
:right [mash :l]
:fullscreen [mash :m]
:nextscreen [mash :n]}]
(Install:andUse :MiroWindowsManager {: hotkeys}))
(Install:andUse :SleepCorners {:config {:feedbackSize 25 :neverSleepCorner "*"}
:start true})
1 year ago
;; 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
;; the URL is opened in Little Arc.
1 year ago
(let [open-in-arc #(urlevent.openURLWithBundle $1 :company.thebrowser.Browser)
handlers {:arc open-in-arc
:firefox-dev :org.mozilla.firefoxdeveloperedition
:firefox :org.mozilla.firefox
:safari :com.apple.Safari
:zoom :us.zoom.xos}
1 year ago
url-patterns [["^https://(.*%.?)zoom.us/j/%d+" handlers.zoom]
1 year ago
["^https://(.*%.?)discnw.org/?" handlers.safari]
["^https://(.*%.?)squareupmessaging.com/?" handlers.safari]
["^https://(.*%.?)bulletin.com/?" handlers.safari]
["^https://(.*%.?)store.apple.com/?" handlers.safari]
["^https://(.*%.?)goodluckbread.com/?" handlers.safari]
["^https://community.glowforge.com/?" handlers.arc]
["^https://accounts.google.com/?" handlers.arc]
5 months ago
["^https://(.*%.?)fidelityinvestments.com/?"
handlers.safari]
["^https://mychartwa.providence.org/?"
handlers.firefox-dev]
["^https://www.bankofamerica.com/?" handlers.safari]]
1 year ago
url-redir-decoders [[:sci-hub
"^https://doi.org/(.*)"
9 months ago
"https://sci-hub.st/%1"]]]
1 year ago
(Install:andUse :URLDispatcher {:config {:url_patterns url-patterns
:url_redir_decoders url-redir-decoders
1 year ago
:default_handler handlers.arc
:set_system_handler true}
: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))
1 year ago
(: (notify.new {:title :Hammerspoon
:informativeText "Config loaded"
:withdrawAfter 2}) :send)