mash-t for terminal

main
Alpha Chen 2 years ago
parent 73d4f310ac
commit fc0c63d52b
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -1,14 +1,30 @@
(local {: mash : smash : modal-bind} (require :hotkey)) (local {: mash : smash : modal-bind} (require :hotkey))
(local log (hs.logger.new :log :info)) (local {: application
(set hs.logger.defaultLogLevel :info) : caffeinate
: eventtap
: execute
: fs
: hotkey
: http
: json
: logger
: loadSpoon
: notify
: pasteboard
: uielement
: usb} hs)
(local log (logger.new :log :info))
(set logger.defaultLogLevel :info)
(set hs.window.animationDuration 0.0) (set hs.window.animationDuration 0.0)
(hs.loadSpoon :MiroWindowsManager) (loadSpoon :MiroWindowsManager)
;; (set spoon.MiroWindowsManager.fullScreenSizes [1 (/ 4 3) 2]) ; only fullscreen ;; (set spoon.MiroWindowsManager.fullScreenSizes [1 (/ 4 3) 2]) ; only fullscreen
;; fnlfmt: skip ;; fnlfmt: skip
(spoon.MiroWindowsManager:bindHotkeys {:up [mash :k] (let [{: MiroWindowsManager} spoon]
(MiroWindowsManager:bindHotkeys {:up [mash :k]
:left [mash :h] :left [mash :h]
:down [mash :j] :down [mash :j]
:right [mash :l] :right [mash :l]
@ -16,48 +32,49 @@
;; :center [mash "c"] ;; :center [mash "c"]
;; :move [smash "m"] ;; :move [smash "m"]
;; :resize [mash "d"] ;; :resize [mash "d"]
}) }))
;; debugging ;; debugging
;; (hs.hotkey.bind mash "d" (fn [] (hs.dialog.blockAlert "message" "text" "one" "two"))) ;; (hotkey.bind mash "d" (fn [] (hs.dialog.blockAlert "message" "text" "one" "two")))
;; (hs.hotkey.bind mash "d" (fn [] (hs.dialog.alert 100 100 (fn [] ) "message" "text" "one" "two"))) ;; (hotkey.bind mash "d" (fn [] (hs.dialog.alert 100 100 (fn [] ) "message" "text" "one" "two")))
;; defeat paste blocking ;; defeat paste blocking
(hs.hotkey.bind [:cmd :alt] :v (hotkey.bind [:cmd :alt] :v #(eventtap.keyStrokes (pasteboard.getContents)))
#(hs.eventtap.keyStrokes (hs.pasteboard.getContents)))
(hotkey.bind mash :e
(hs.hotkey.bind mash :e #(let [app (application.frontmostApplication)
#(let [app (hs.application.frontmostApplication) prev-pasteboard (pasteboard.getContents)
prev-pasteboard (hs.pasteboard.getContents) e (uielement.focusedElement)
e (hs.uielement.focusedElement) text (if e (e:selectedText)
text (if e (e:selectedText) (do
(do (eventtap.keyStroke [:cmd] :c)
(hs.eventtap.keyStroke [:cmd] :c) (pasteboard.getContents)))
(hs.pasteboard.getContents))) date (execute "date -Iseconds -u | tr -d '\n'")
date (hs.execute "date -Iseconds -u | tr -d '\n'") file (.. "~/.quickcursor." date)]
file (.. "~/.quickcursor." date)] (pasteboard.setContents text)
(hs.pasteboard.setContents text) (execute (.. "pbpaste > " file))
(hs.execute (.. "pbpaste > " file)) (execute (.. "/opt/homebrew/bin/neovide --nofork " file))
(hs.execute (.. "/opt/homebrew/bin/neovide --nofork " file)) (execute (.. "pbcopy < " file))
(hs.execute (.. "pbcopy < " file)) (app:setFrontmost)
(app:setFrontmost) (eventtap.keyStroke [:cmd] :v)
(hs.eventtap.keyStroke [:cmd] :v) (execute (.. "rm " file))
(hs.execute (.. "rm " file)) (pasteboard.setContents prev-pasteboard)))
(hs.pasteboard.setContents prev-pasteboard)))
(hotkey.bind mash :t #(execute :/opt/homebrew/bin/alacritty))
(fn linkify [] (fn linkify []
(let [app (hs.application.frontmostApplication) (let [app (application.frontmostApplication)
prev-pasteboard (hs.pasteboard.getContents) prev-pasteboard (pasteboard.getContents)
e (hs.uielement.focusedElement) e (uielement.focusedElement)
text (if e (e:selectedText) text (if e (e:selectedText)
(do (do
(hs.eventtap.keyStroke [:cmd] :c) (eventtap.keyStroke [:cmd] :c)
(hs.pasteboard.getContents))) (pasteboard.getContents)))
link (.. "[" text "]" "(" prev-pasteboard ")")] link (.. "[" text "]" "(" prev-pasteboard ")")]
(hs.pasteboard.setContents link) (pasteboard.setContents link)
(app:setFrontmost) (app:setFrontmost)
(hs.eventtap.keyStroke [:cmd] :v) (eventtap.keyStroke [:cmd] :v)
(hs.pasteboard.setContents prev-pasteboard))) (pasteboard.setContents prev-pasteboard)))
(modal-bind mash "," nil [[mash :l nil linkify]]) (modal-bind mash "," nil [[mash :l nil linkify]])
@ -72,14 +89,14 @@
(fn update-key-light-air [on?] (fn update-key-light-air [on?]
(let [url "http://elgato-key-light-air-5c9e.local:9123/elgato/lights" (let [url "http://elgato-key-light-air-5c9e.local:9123/elgato/lights"
on (if on? 1 0) on (if on? 1 0)
data (hs.json.encode {:lights [{: on}]})] data (json.encode {:lights [{: on}]})]
(hs.http.doRequest url :PUT data))) (http.doRequest url :PUT data)))
(fn docked? [] (fn docked? []
(accumulate [docked? false _ v (pairs (hs.usb.attachedDevices)) &until docked?] (accumulate [docked? false _ v (pairs (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 (let [{: watcher} hs.caffeinate (local key-light-air-watcher (let [{: watcher} caffeinate
w (watcher.new #(when (docked?) w (watcher.new #(when (docked?)
(match $1 (match $1
watcher.screensDidLock (update-key-light-air false) watcher.screensDidLock (update-key-light-air false)
@ -88,7 +105,7 @@
watcher.screensDidWake (update-key-light-air true))))] watcher.screensDidWake (update-key-light-air true))))]
(w:start))) (w:start)))
; (local usb-watcher (: (hs.usb.watcher.new #(let [{: eventType : productName} $1] ; (local usb-watcher (: (usb.watcher.new #(let [{: eventType : productName} $1]
; (when (= productName ; (when (= productName
; "CalDigit Thunderbolt 3 Audio") ; "CalDigit Thunderbolt 3 Audio")
; (match eventType ; (match eventType
@ -102,13 +119,13 @@
;;; Spoons ;;; Spoons
(: (hs.loadSpoon :ReloadConfiguration) :start) (: (loadSpoon :ReloadConfiguration) :start)
;; Local overrides ;; Local overrides
(when (hs.fs.attributes :local.fnl) (when (fs.attributes :local.fnl)
(require :local)) (require :local))
(: (hs.notify.new {:title :Hammerspoon (: (notify.new {:title :Hammerspoon
:informativeText "Config loaded" :informativeText "Config loaded"
:withdrawAfter 2}) :send) :withdrawAfter 2}) :send)

Loading…
Cancel
Save