Last active
January 21, 2021 18:05
-
-
Save ddresselhaus/98b022e295bc27e9264dece7823e74e8 to your computer and use it in GitHub Desktop.
run Elixir tests in a separate tmux pane
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
" when triggering this command, vim will grab your path and line location and pass it along | |
map <Leader>el :call RemoteSendCommand(TestLineCommand(expand("%:p"), line(".")))<CR> | |
" because I'm mostly writing Elixir and making heavy use of the REPL while writing my tests, | |
" I made a specific command to user with Mix, the Elixir task utility | |
" But I'm sure you could get this to work with vim-test or something like that | |
function! TestLineCommand(path, line_number) | |
let cmd = join(["mix test --only", " line:", a:line_number, " ", a:path], "") | |
return cmd | |
endfunction | |
" Here, we're sending it to the last pane | |
function! RemoteSendCommand(cmd) | |
let pane = system("tmux display-message -p '#{window_panes}'") | |
let new_pane = substitute(pane, '[^0-9]', '', '') | |
echom "! tmux send-keys -t " . new_pane . " \" " . a:cmd . "\" C-m" | |
execute "! tmux send-keys -t " . new_pane . " \" " . a:cmd . "\" C-m" | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I run into an error where the pane cannot be found. The pane is always indexed with the number of open panes. I feel like I'm not understanding something.