[hammerspoon][alfred] move edit-in-vim to Hammerspoon from Alfred
change
commit 1a97b467fd1e059b642f05b2523a64b89e1b65ba
author Alpha Chen <alpha@kejadlen.dev>
date
parent 4f0f9e94
diff --git a/.hammerspoon/init.fnl b/.hammerspoon/init.fnl
index c76c830a..e2765f74 100644
--- a/.hammerspoon/init.fnl
+++ b/.hammerspoon/init.fnl
@@ -1,31 +1,49 @@
 (local log (hs.logger.new "log" "info"))
+(set hs.logger.defaultLogLevel "info")
+
+(local mash [:cmd :alt :ctrl])
+(local smash [:cmd :alt :ctrl :shift])
 
 (set hs.window.animationDuration 0.0)
 (hs.loadSpoon "MiroWindowsManager")
 ;; (set spoon.MiroWindowsManager.fullScreenSizes [1 (/ 4 3) 2]) ;; only fullscreen
-(let [mash [:cmd :alt :ctrl]
-      smash [:cmd :alt :ctrl :shift]]
-  (spoon.MiroWindowsManager:bindHotkeys {
-    :up         [ mash  "k" ]
-    :left       [ mash  "h" ]
-    :down       [ mash  "j" ]
-    :right      [ mash  "l" ]
-    :fullscreen [ mash  "m" ]
-    ;; :center     [ mash  "c" ]
-    ;; :move       [ smash "m" ]
-    ;; :resize     [ mash  "d" ]
-  }))
-
-(let [mash [:cmd :alt :ctrl]
-      smash [:cmd :alt :ctrl :shift]]
-
-  ;; debugging
-  ;; (hs.hotkey.bind mash "d" (fn []))
-
-  ;; defeat paste blocking
-  (hs.hotkey.bind [:cmd :alt] "v" (fn [] (hs.eventtap.keyStrokes (hs.pasteboard.getContents)))))
+(spoon.MiroWindowsManager:bindHotkeys {
+  :up         [ mash  "k" ]
+  :left       [ mash  "h" ]
+  :down       [ mash  "j" ]
+  :right      [ mash  "l" ]
+  :fullscreen [ mash  "m" ]
+  ;; :center     [ mash  "c" ]
+  ;; :move       [ smash "m" ]
+  ;; :resize     [ mash  "d" ]
+})
 
-(set hs.logger.defaultLogLevel "info")
+;; debugging
+;; (hs.hotkey.bind mash "d" (fn []))
+;; (hs.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")))
+
+;; defeat paste blocking
+(hs.hotkey.bind [:cmd :alt] "v" (fn [] (hs.eventtap.keyStrokes (hs.pasteboard.getContents))))
+
+(hs.hotkey.bind mash "e" (fn []
+  (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)))
+        date (hs.execute "date -Iseconds -u | tr -d '\n'")
+        file (.. "~/.quickcursor." date)]
+    (hs.pasteboard.setContents text)
+    (hs.execute (.. "pbpaste > " file))
+    (hs.execute (.. "/opt/homebrew/bin/mvim --nofork " file))
+    (hs.execute (.. "pbcopy < " file))
+    (app:setFrontmost)
+    (hs.eventtap.keyStroke [:cmd] "v")
+    (hs.execute (.. "rm " file))
+    (hs.pasteboard.setContents prev-pasteboard))))
 
 (set hs.urlevent.httpCallback
   (fn [scheme host params fullURL]
diff --git a/Alfred.alfredpreferences/workflows/user.workflow.02B3D711-234D-45C7-99C1-98C8D4604DCC/info.plist b/Alfred.alfredpreferences/workflows/user.workflow.02B3D711-234D-45C7-99C1-98C8D4604DCC/info.plist
index 187cef8d..7cf4d9c2 100644
--- a/Alfred.alfredpreferences/workflows/user.workflow.02B3D711-234D-45C7-99C1-98C8D4604DCC/info.plist
+++ b/Alfred.alfredpreferences/workflows/user.workflow.02B3D711-234D-45C7-99C1-98C8D4604DCC/info.plist
@@ -29,7 +29,7 @@
 	<key>description</key>
 	<string></string>
 	<key>disabled</key>
-	<false/>
+	<true/>
 	<key>name</key>
 	<string>Edit in MacVim</string>
 	<key>objects</key>
@@ -62,7 +62,7 @@ SCRIPT
 
 File.write(filename, query)
 begin
-  `/usr/local/bin/mvim --nofork #{filename}`
+  `/opt/homebrew/bin/mvim --nofork #{filename}`
   `cat #{filename} | pbcopy`
   osascript(&lt;&lt;-SCRIPT)
     tell application "#{app}"