Skip to content

Instantly share code, notes, and snippets.

@ddresselhaus
Last active January 21, 2021 18:05
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ddresselhaus/98b022e295bc27e9264dece7823e74e8 to your computer and use it in GitHub Desktop.
Save ddresselhaus/98b022e295bc27e9264dece7823e74e8 to your computer and use it in GitHub Desktop.
run Elixir tests in a separate tmux pane
" 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
@rel1c
Copy link

rel1c commented Jan 21, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment