more general command escaper than just tests
This commit is contained in:
parent
f6a4e9907a
commit
0bd8c18086
80
vim/execute.vim
Normal file
80
vim/execute.vim
Normal file
@ -0,0 +1,80 @@
|
||||
let escapeTmuxSession = "vim-exec"
|
||||
let escapeTmuxPaneID = g:escapeTmuxSession . ":0.0"
|
||||
|
||||
let escapeCommandOutputs = ['tmux', 'split-pane-vertical', 'split-pane-horizontal']
|
||||
|
||||
function ExecuteCommand(args = '', output = '', flavor = 'shell')
|
||||
let output = a:output
|
||||
if output == ''
|
||||
let output = GetPrefferredCommandOutput()
|
||||
endif
|
||||
|
||||
let command = GetCommandString(a:args, a:flavor, output)
|
||||
|
||||
if output == 'tmux'
|
||||
silent call EnsureTmuxSession()
|
||||
call system("tmux send-keys -t ".g:escapeTmuxPaneID." '".command."' Enter")
|
||||
silent call system("tmux display-popup -E 'tmux a -t ".g:escapeTmuxSession."' &")
|
||||
elseif output == 'split-pane-horizontal'
|
||||
execute "botright terminal " . command
|
||||
elseif output == 'split-pane-vertical'
|
||||
execute "botright vertical terminal " . command
|
||||
else
|
||||
execute "!" . command
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function GetCommandString(args, flavor, output)
|
||||
let command = ''
|
||||
let gitRoot = FindGitRoot()
|
||||
|
||||
if a:flavor == 'shell'
|
||||
let command = a:args
|
||||
|
||||
elseif a:flavor == 'npm'
|
||||
let command = 'npm test ' . a:args
|
||||
if gitRoot != ''
|
||||
let command = 'cd ' . gitRoot . '; ' . command
|
||||
endif
|
||||
|
||||
elseif a:flavor == 'django'
|
||||
let command = './manage.py test --keepdb ' . a:args
|
||||
if gitRoot != ''
|
||||
let command = 'cd ' . gitRoot . '; ' . command
|
||||
endif
|
||||
endif
|
||||
|
||||
if stridx(a:output, 'tmux') != -1
|
||||
let command = command.";"
|
||||
\ . "echo \"-----------------------------\" | lolcat;"
|
||||
\ . "echo \"(ENTER to close, C^c to stay)\";"
|
||||
\ . "read </dev/tty;"
|
||||
\ . "tmux detach-client -s".g:escapeTmuxSession.";"
|
||||
endif
|
||||
|
||||
if stridx(a:output, 'split-pane') == -1
|
||||
let command = "clear; ".command
|
||||
endif
|
||||
|
||||
return command
|
||||
endfunction
|
||||
|
||||
function GetPrefferredCommandOutput()
|
||||
for output in g:escapeCommandOutputs
|
||||
if stridx(output, 'tmux') && executable('tmux')
|
||||
return output
|
||||
elseif stridx(output, 'split-pane') != -1 && v:version >= 800
|
||||
return output
|
||||
endif
|
||||
endfor
|
||||
|
||||
return 'shell-escape'
|
||||
endfunction
|
||||
|
||||
function EnsureTmuxSession()
|
||||
call system("tmux new -ds " . g:escapeTmuxSession . " -c $HOME >/dev/null 2>&1")
|
||||
endfunction
|
||||
|
||||
function FindGitRoot()
|
||||
return finddir('.git/..', expand('%:p:h').';')
|
||||
endfunction
|
@ -14,6 +14,7 @@ function FormatFileType(indent, expandtab, foldmethod, foldlevel, spell)
|
||||
endfunction
|
||||
|
||||
augroup forced_filetype_recognition
|
||||
autocmd!
|
||||
autocmd BufRead,BufNewFile *.tmux setfiletype tmux
|
||||
autocmd BufRead,BufNewFile *.clisp setfiletype lisp
|
||||
autocmd BufRead,BufNewFile *.lsp setfiletype lisp
|
||||
@ -64,7 +65,8 @@ let g:markdown_fenced_languages = ['javascript', 'json', 'python', 'bash', 'yaml
|
||||
" (t)ests
|
||||
" {{{
|
||||
augroup file_specific_command_overrides
|
||||
nnoremap <Leader>ec :call SplitPaneTest('%:p', v:true)<CR>
|
||||
autocmd!
|
||||
nnoremap <Leader>ec :call ExecuteCommand('%:p', 'split-pane-horizontal')<CR>
|
||||
nnoremap <Leader>ei :echohl ErrorMsg <bar> echom 'ERROR: no interactive execute defined' <bar> echohl None<CR>
|
||||
nnoremap <Leader>eb :echohl ErrorMsg <bar> echom 'ERROR: no build steps defined' <bar> echohl None<CR>
|
||||
nnoremap <Leader>ef :echohl ErrorMsg <bar> echom 'ERROR: no auto-format steps defined' <bar> echohl None<CR>
|
||||
@ -80,8 +82,8 @@ augroup file_specific_command_overrides
|
||||
autocmd FileType go nnoremap <silent> <Leader>ef <Plug>(go-imports)
|
||||
autocmd FileType go nnoremap <silent> gd <Plug>(go-def-tab)
|
||||
|
||||
autocmd FileType python nnoremap <Leader>ec :call SplitPaneTest('bpython %')<CR>
|
||||
autocmd FileType python nnoremap <Leader>ei :call SplitPaneTest('bpython -qi %')<CR>
|
||||
autocmd FileType python nnoremap <Leader>ec :call ExecuteCommand('bpython %:p', 'split-pane-vertical')<CR>
|
||||
autocmd FileType python nnoremap <Leader>ei :call ExecuteCommand('bpython -qi %:p', 'split-pane-vertical')<CR>
|
||||
augroup end
|
||||
" }}}
|
||||
|
||||
|
10
vim/rc.vim
10
vim/rc.vim
@ -5,7 +5,7 @@ if isdirectory(expand("$HOME/.vim/bundle/Vundle.vim"))
|
||||
endif
|
||||
|
||||
source $WRYNVIMPATH/options.vim
|
||||
source $WRYNVIMPATH/testing.vim
|
||||
source $WRYNVIMPATH/execute.vim
|
||||
source $WRYNVIMPATH/formatting.vim
|
||||
source $WRYNVIMPATH/navigation.vim
|
||||
source $WRYNVIMPATH/color.vim
|
||||
@ -49,10 +49,10 @@ nnoremap <Leader>gb :Git blame<CR>
|
||||
|
||||
" \r = open last REPL (p)ython (n)odejs (c)lisp
|
||||
nnoremap <Leader>r q:?^echom 'quickrepl'<CR><CR>
|
||||
nnoremap <Leader>rp q:oechom 'quickrepl' \| call SplitPaneTest('bpython')<CR>
|
||||
nnoremap <Leader>rn q:oechom 'quickrepl' \| call SplitPaneTest('node')<CR>
|
||||
nnoremap <Leader>rc q:oechom 'quickrepl' \| call SplitPaneTest('clisp', 1)<CR>
|
||||
nnoremap <Leader>rs q:oechom 'quickrepl' \| call SplitPaneTest('')<CR>
|
||||
nnoremap <Leader>rp q:oechom 'quickrepl' \| call ExecuteCommand('bpython', 'split-pane-vertical')<CR>
|
||||
nnoremap <Leader>rn q:oechom 'quickrepl' \| call ExecuteCommand('node', 'split-pane-vertical')<CR>
|
||||
nnoremap <Leader>rc q:oechom 'quickrepl' \| call ExecuteCommand('clisp', 'split-pane-horizontal')<CR>
|
||||
nnoremap <Leader>rs q:oechom 'quickrepl' \| call ExecuteCommand('zsh -l', 'split-pane-vertical')<CR>
|
||||
|
||||
" \t = run last quicktest
|
||||
" t)ype new quicktest
|
||||
|
125
vim/testing.vim
125
vim/testing.vim
@ -1,125 +0,0 @@
|
||||
|
||||
let tmuxTestSessionName = "test"
|
||||
let defaultTmuxPaneId = g:tmuxTestSessionName . ":0.0"
|
||||
|
||||
function InitializeTmuxTestSession()
|
||||
call system("tmux new -ds " . g:tmuxTestSessionName . " -c $HOME >/dev/null 2>&1")
|
||||
endfunction
|
||||
|
||||
|
||||
" ===================================================================
|
||||
" === test formats ==================================================
|
||||
" ===================================================================
|
||||
|
||||
function TmuxTest(shellCommand, paneId = g:defaultTmuxPaneId)
|
||||
if a:paneId == g:defaultTmuxPaneId
|
||||
silent call InitializeTmuxTestSession()
|
||||
endif
|
||||
|
||||
call system("tmux send-keys -t " . a:paneId . " 'clear; " . a:shellCommand . "' Enter")
|
||||
endfunction
|
||||
|
||||
function SplitPaneTest(shellCommand, horizontal = v:false)
|
||||
if a:horizontal
|
||||
execute "botright terminal " . a:shellCommand
|
||||
else
|
||||
execute "botright vertical terminal " . a:shellCommand
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function ShellEscapedTest(shellCommand)
|
||||
execute "!" . a:shellCommand
|
||||
endfunction
|
||||
|
||||
|
||||
" ===================================================================
|
||||
" === python-django =================================================
|
||||
" ===================================================================
|
||||
|
||||
function DjangoTmuxTest(paneId = g:defaultTmuxPaneId)
|
||||
let l:command = "cd " . getcwd() . "; " . GetDjangoTestCommand()
|
||||
call TmuxTest(l:command, a:paneId)
|
||||
endfunction
|
||||
|
||||
function DjangoSplitTest(horizontal = v:false)
|
||||
let l:command = GetDjangoTestCommand()
|
||||
call SplitPaneTest(l:command, a:horizontal)
|
||||
endfunction
|
||||
|
||||
function DjangoTest()
|
||||
let l:command = GetDjangoTestCommand()
|
||||
call ShellEscapedTest(l:command)
|
||||
endfunction
|
||||
|
||||
|
||||
function GetDjangoTestCommand()
|
||||
return GetDjangoManagePy() . " test --keepdb"
|
||||
endfunction
|
||||
|
||||
function GetDjangoManagePy()
|
||||
return substitute(expand(getcwd()), "/code.*", "/code/manage.py", "")
|
||||
endfunction
|
||||
|
||||
|
||||
" ===================================================================
|
||||
" === dotnet core ===================================================
|
||||
" ===================================================================
|
||||
|
||||
function DotnetTest(filter = '')
|
||||
let l:command =
|
||||
\ 'cd ' . GetDotnetProjectLocation()
|
||||
\ . ';' . 'dotnet build -clp:ErrorsOnly'
|
||||
\ . ';' . 'cd ' . GetDotnetProjectLocation(1)
|
||||
\ . ';' . 'dotnet test -clp:ErrorsOnly'
|
||||
if a:filter != ''
|
||||
let l:command = l:command . ' --filter ' . a:filter
|
||||
endif
|
||||
call TmuxTest(l:command)
|
||||
endfunction
|
||||
|
||||
function DotnetBuild()
|
||||
let l:command =
|
||||
\ 'cd ' . GetDotnetProjectLocation()
|
||||
\ . ';' . 'dotnet build -clp:ErrorsOnly'
|
||||
|
||||
call TmuxTest(l:command)
|
||||
endfunction
|
||||
|
||||
function GetDotnetProjectLocation(test = v:false)
|
||||
let l:projectRoot = substitute(expand(getcwd()), '/code.*', '/code', '')
|
||||
let l:projectName = substitute(expand(getcwd()), l:projectRoot . '/\([^/]*\).*', '\1', '')
|
||||
if a:test
|
||||
let l:testPath = system('ls ' . l:projectRoot . '/**/*.csproj | grep Test | head -1')
|
||||
else
|
||||
if l:projectName != ''
|
||||
let l:testPath = l:projectRoot . '/' . l:projectName
|
||||
else
|
||||
let l:testPath = system('ls ' . l:projectRoot . '/**/*.csproj | grep -v Test | head -1')
|
||||
endif
|
||||
endif
|
||||
return substitute(l:testPath, '\(.*\)/.*.csproj.*', '\1', '')
|
||||
endfunction
|
||||
|
||||
" ===================================================================
|
||||
" === npm ===========================================================
|
||||
" ===================================================================
|
||||
|
||||
function NpmTmuxTest(paneId = g:defaultTmuxPaneId)
|
||||
let l:command = "cd " . getcwd() . "; " . GetNpmTestCommand()
|
||||
call TmuxTest(l:command, a:paneId)
|
||||
endfunction
|
||||
|
||||
function NpmSplitTest(horizontal = v:false)
|
||||
let l:command = GetNpmTestCommand()
|
||||
call SplitPaneTest(l:command, a:horizontal)
|
||||
endfunction
|
||||
|
||||
function NpmTest()
|
||||
let l:command = GetNpmTestCommand()
|
||||
call ShellEscapedTest(l:command)
|
||||
endfunction
|
||||
|
||||
|
||||
function GetNpmTestCommand()
|
||||
return "npm test"
|
||||
endfunction
|
Loading…
Reference in New Issue
Block a user