Created
May 31, 2022 10:05
-
-
Save hangyas/57720b6ce9b5dc0c629d264cda6bf370 to your computer and use it in GitHub Desktop.
Run ExUnit test in kitty with joyride
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns kitty | |
(:require ["vscode" :as vscode] | |
[joyride.core :as joyride] | |
["child_process" :as child-process])) | |
;; This script runs the selected ExUnit test in a kitty terminal | |
;; as `mix test <file>:<line>` | |
;; requires kitty to be started as `kitty --listen-on unix:/tmp/mykitty` | |
;; config the unix channel where kitty is accessed | |
(def kitty "kitty @ --to unix:/tmp/mykitty ") | |
(def exec (.-exec child-process)) | |
(defn root-path [] (. vscode.workspace -rootPath)) | |
;; select a kitty window with cwd matching the project root | |
(def window-selector (str " --match cwd:" (root-path) " ")) | |
(defn file-path [] | |
(let [root (root-path) | |
path (. vscode.window.activeTextEditor.document -fileName)] | |
(if (.startsWith path root) | |
(.replace path (str root "/") "") | |
path))) | |
(defn line-number [] (. vscode.window.activeTextEditor.selection.active -line)) | |
(defn focus | |
[] | |
(exec (str kitty "focus-window" window-selector))) | |
(defn send-text | |
[text] | |
(exec (str kitty "send-text" window-selector text))) | |
(defn send-command | |
[command] | |
(send-text (str "\"" command "\n\""))) | |
(defn my-main [] | |
(send-command (str "mix test " (file-path) ":" (line-number) "\n")) | |
(focus)) | |
(when (joyride/invoked-script) | |
(my-main)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment