Skip to content

Instantly share code, notes, and snippets.

@hangyas
Created May 31, 2022 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hangyas/57720b6ce9b5dc0c629d264cda6bf370 to your computer and use it in GitHub Desktop.
Save hangyas/57720b6ce9b5dc0c629d264cda6bf370 to your computer and use it in GitHub Desktop.
Run ExUnit test in kitty with joyride
(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