From 039c03b6b53a5b057eb241cd5c2f039e213c8544 Mon Sep 17 00:00:00 2001 From: yage Date: Mon, 13 Nov 2023 16:35:35 -0700 Subject: [PATCH] vim execute overhaul --- vim/execute.vim | 8 ++++- vim/file-execute.vim | 62 ++++++++++++++++++++++++++++++++++++ vim/formatting.vim | 66 ++------------------------------------- vim/override/directus.vim | 2 ++ vim/rc.vim | 4 +++ 5 files changed, 77 insertions(+), 65 deletions(-) create mode 100644 vim/file-execute.vim diff --git a/vim/execute.vim b/vim/execute.vim index 0e18e70..4274d82 100644 --- a/vim/execute.vim +++ b/vim/execute.vim @@ -4,7 +4,13 @@ let escapeTmuxPaneID = g:escapeTmuxSession . ":0.0" let escapeCommandOutputs = ['tmux', 'split-pane-vertical', 'split-pane-horizontal'] function ExecuteScwrypt(scwrypt = '', args = '', output = '', syntax = 'bash') - call ExecuteCommand('scwrypts ' . a:scwrypt . ' -- ' . a:args, a:output, 'shell', a:syntax) + let b:scwryptsPrevArgs = a:args + call ExecuteCommand('scwrypts -n ' . a:scwrypt . ' -- ' . a:args, a:output, 'shell', a:syntax) + echom 'scwrypts -n ' . a:scwrypt . '--' . a:args +endfunction + +function ExecuteScwryptInteractive(scwrypt = '', args = '', output = '', syntax = 'bash') + call ExecuteScwrypt(a:scwrypt, a:args . input('scwrypts ' . a:scwrypt . '--' . a:args), a:output, a:syntax) endfunction function ExecuteCommand(args = '', output = '', flavor = 'shell', syntax = 'bash') diff --git a/vim/file-execute.vim b/vim/file-execute.vim new file mode 100644 index 0000000..39406a6 --- /dev/null +++ b/vim/file-execute.vim @@ -0,0 +1,62 @@ +nnoremap ec :execute b:executeDefault +nnoremap ei :execute b:executeInteractive +nnoremap eb :execute b:executeBuild +nnoremap ef :execute b:executeFormat +nnoremap et :execute b:executeTest + +" --- (e)xe(c)ute ----------------------------------------------------- +" (i)nteractive +" (b)uild +" auto-(f)ormat +" (t)ests +" {{{ +augroup file_specific_commands + autocmd! + + autocmd FileType * let b:executeDefault = "call ExecuteCommand('%:p', 'split-pane-horizontal')" + autocmd FileType * let b:executeInteractive = "call ExecuteCommand('%:p ' . input(expand('%').' -- '), 'split-pane-horizontal')" + autocmd FileType * let b:executeBuild = "echohl ErrorMsg | echom 'ERROR: no build steps defined' | echohl None" + autocmd FileType * let b:executeFormat = "%s/\\s\\+$//" + autocmd FileType * let b:executeTest = "echohl ErrorMsg | echom 'ERROR: no test steps defined' | echohl None" + + autocmd FileType go let b:executeDefault = "!clearq:?GoRun" + autocmd FileType go let b:executeFormat = "(go-imports)" + autocmd FileType go nnoremap gd (go-def-tab) + + autocmd FileType markdown let b:executeDefault = '!google-chrome-stable %:p' + + autocmd FileType python let b:executeDefault = "call ExecuteCommand('python %:p', 'split-pane-vertical')" + autocmd FileType python let b:executeInteractive = "call ExecuteCommand('bpython -qi %:p ' . input(expand('%').' -- '), 'split-pane-vertical')" + + autocmd FileType tex let b:executeDefault = 'call ExecuteScwrypt("latex/open-pdf", "%:p")' + autocmd FileType tex let b:executeBuild = 'call ExecuteScwrypt("latex/build-pdf", "%:p")' + autocmd FileType tex let b:executeFormat = 'call ExecuteScwrypt("latex/cleanup", "%:p")' + + autocmd FileType yaml let b:scwryptDefault = "--group scwrypts --type zsh --name helm/get-template " + autocmd FileType yaml let b:scwryptBuild = "--group scwrypts --type zsh --name helm/update-dependencies " + autocmd FileType yaml let b:scwryptArgs = "--template-filename %:p " + autocmd FileType yaml let b:executeDefault = 'call ExecuteScwrypt(b:scwryptDefault, b:scwryptArgs . "--raw ", "split-pane-vertical", "yaml")' + autocmd FileType yaml let b:executeInteractive = 'call ExecuteScwryptInteractive(b:scwryptDefault, b:scwryptArgs, "split-pane-vertical", "yaml")' + autocmd FileType yaml let b:executeBuild = 'call ExecuteScwrypt(b:scwryptBuild, b:scwryptArgs, "split-pane-vertical", "yaml")' + autocmd FileType yaml let b:executeTest = 'call ExecuteScwrypt(b:scwryptDefault, b:scwryptArgs, "split-pane-vertical", "yaml")' + + " --- OVERRIDES ---------------------------- " + + autocmd FileType *.scwrypts let b:scwryptsType = "" + autocmd FileType zsh.scwrypts let b:scwryptsType = "zsh" + autocmd FileType python.scwrypts let b:scwryptsType = "py" + autocmd FileType javascript.scwrypts let b:scwryptsType = "zx" + autocmd FileType typescript.scwrypts let b:scwryptsType = "zx" + + autocmd FileType *.scwrypts let b:scwryptsSubPath = substitute(substitute(expand("%:p"), ".*\.scwrypts/", "", ""), "^".b:scwryptsType."/", "", "") + autocmd FileType *.scwrypts let b:scwryptsAutoName = b:scwryptsType . " " . substitute(substitute(b:scwryptsSubPath, ".[a-z]\\+$", "", ""), "/", " ", "g") . " " + autocmd FileType *.scwrypts let b:scwryptsPrevArgs = ' ' + autocmd FileType *.scwrypts let b:scwryptsEnvs = split(system('scwrypts --list-envs'), '\n') + autocmd FileType *.scwrypts let b:scwryptsEnvChoices = split(system('echo SCWRYPTS_ENV=; scwrypts --list-envs | awk "{print \"\"NR\". \"\$0}"'), '\n') + + autocmd FileType *.scwrypts let b:executeDefault = "call ExecuteScwrypt(b:scwryptsAutoName, ' ', 'split-pane-vertical')" + autocmd FileType *.scwrypts let b:executeInteractive = "call ExecuteScwryptInteractive(b:scwryptsAutoName, ' ', 'split-pane-vertical')" + autocmd FileType *.scwrypts let b:executeBuild = "let $SCWRYPTS_ENV=b:scwryptsEnvs[inputlist(b:scwryptsEnvChoices) - 1]" + autocmd FileType *.scwrypts let b:executeTest = "call ExecuteScwrypt(b:scwryptsAutoName, b:scwryptsPrevArgs, 'split-pane-vertical')" +augroup end +" }}} diff --git a/vim/formatting.vim b/vim/formatting.vim index 1e351da..dc5a436 100644 --- a/vim/formatting.vim +++ b/vim/formatting.vim @@ -23,6 +23,8 @@ augroup forced_filetype_recognition autocmd BufRead,BufNewFile *.template.yaml set filetype=yaml.cloudformation autocmd BufRead,BufNewFile git.conf setfiletype gitconfig + autocmd BufRead,BufNewFile */scwrypts/* execute "set filetype=".&filetype.".scwrypts" + let g:tex_flavor = "latex" augroup end @@ -58,68 +60,4 @@ augroup end let g:markdown_fenced_languages = ['javascript', 'json', 'python', 'bash', 'yaml', 'shell=zsh', 'sql'] " }}} - -" --- (e)xe(c)ute ----------------------------------------------------- -" (i)nteractive -" (b)uild -" auto-(f)ormat -" (t)ests -" {{{ -augroup file_specific_command_overrides - autocmd! - nnoremap ec :call ExecuteCommand('%:p', 'split-pane-horizontal') - nnoremap ei :echohl ErrorMsg echom 'ERROR: no interactive execute defined' echohl None - nnoremap eb :echohl ErrorMsg echom 'ERROR: no build steps defined' echohl None - nnoremap ef :echohl ErrorMsg echom 'ERROR: no auto-format steps defined' echohl None - nnoremap et :echohl ErrorMsg echom 'ERROR: no test steps defined' echohl None - - autocmd FileType tex nnoremap ec :! scwrypts -n latex/open-pdf -- %:p - autocmd FileType tex nnoremap eb :! scwrypts -n latex/build-pdf -- %:p - autocmd FileType tex nnoremap ef :! scwrypts -n latex/cleanup -- %:p - - autocmd FileType markdown nnoremap ec :!xdg-open %:p - - autocmd FileType go nnoremap ec :!clearq:?GoRun - autocmd FileType go nnoremap ef (go-imports) - autocmd FileType go nnoremap gd (go-def-tab) - - autocmd FileType python nnoremap ec :call ExecuteCommand('python %:p', 'split-pane-vertical') - autocmd FileType python nnoremap ei :call ExecuteCommand('bpython -qi %:p', 'split-pane-vertical') - - autocmd FileType yaml nnoremap ec :call ExecuteScwrypt( - \ '-n --name helm/get-template --group scwrypts --type zsh' - \ , '--template-filename %:p', 'split-pane-vertical' - \ , 'yaml' - \) - autocmd FileType yaml nnoremap ei :call ExecuteScwrypt( - \ '-n --name helm/get-template --group scwrypts --type zsh' - \ , '--raw --template-filename %:p', 'split-pane-vertical' - \ , 'yaml' - \) - autocmd FileType yaml nnoremap eb :call ExecuteScwrypt( - \ '-n --name helm/update-dependencies --group scwrypts --type zsh' - \ , '--template-filename %:p', 'split-pane-vertical' - \ , 'yaml' - \) -augroup end -" }}} - -" --- notes for meeeeee ---- -" {{{ -" need to adapt this for helm execution; -" should check for values.test.yaml or tests/default.yaml -" echom 'quicktest' | execute 'vertical terminal helm template directus . --debug --values values.yaml --values values.test.yaml --show-only %' | set syntax=yaml -" }}} - -" --- organization overrides ------------------------------------------ -" {{{ - -source $WRYNVIMPATH/override/rentdynamics.vim -source $WRYNVIMPATH/override/directus.vim - -" }}} -" -" - - syntax on diff --git a/vim/override/directus.vim b/vim/override/directus.vim index eee91e8..eb5c167 100644 --- a/vim/override/directus.vim +++ b/vim/override/directus.vim @@ -3,4 +3,6 @@ augroup directus autocmd BufRead,BufEnter,BufNewFile */Projects/directus/*.js setlocal noexpandtab autocmd BufRead,BufEnter,BufNewFile */Projects/directus/*.mjs setlocal noexpandtab autocmd BufRead,BufEnter,BufNewFile */Projects/directus/*.ts setlocal noexpandtab + + autocmd BufRead,BufNewFile */Projects/directus/cloud/code/scwrypts/* let b:scwryptsAutoName = "directus " . b:scwryptsAutoName augroup end diff --git a/vim/rc.vim b/vim/rc.vim index 393992b..9c9d8de 100644 --- a/vim/rc.vim +++ b/vim/rc.vim @@ -7,10 +7,14 @@ endif source $WRYNVIMPATH/options.vim source $WRYNVIMPATH/execute.vim source $WRYNVIMPATH/formatting.vim +source $WRYNVIMPATH/file-execute.vim source $WRYNVIMPATH/navigation.vim source $WRYNVIMPATH/color.vim source $WRYNVIMPATH/utility.vim +source $WRYNVIMPATH/override/rentdynamics.vim +source $WRYNVIMPATH/override/directus.vim + " --------------------------------------------------------------------- " {{{