我目前正在使用以下映射,基本上通过执行脚本将我的 dev env 中编写的任何文件复制到我的本地服务器。它适用于单个文件。但是,我有做 :wa 来保存所有打开的缓冲区的习惯:
au BufWritePost /path/to/dev/* silent !$HOME/bin/somescript.sh %:p
关于如何将其重写为条件的任何建议,例如:
if one file
exec script to copy just that file # like I already have
if :wa
# here I'd probably exec a script to just copy recursively
编辑
每个 ZyX 解决方案的可能解决方案:
au BufWritePost /Users/rlevin/programming/sugar/Mango/sidecar/* silent !$HOME/bin/sugarbuild.sh %:p
" If we do :wa<CR> we check if command type is ':' and if command itself was
" 'wa'. If so, we call the command WA which calls BuildSidecarIfInProject.
" This checks if we're actually within the project's directory
cnoreabbrev <expr> wa ((getcmdtype() is# ':' && getcmdline() is# 'wa')?('WA'):('wa'))
command! WA :call BuildSidecarIfInProject()
function! BuildSidecarIfInProject()
if fnamemodify('.', ':p')[:44] is# '/Users/rlevin/programming/sugar/Mango/sidecar'
exec ":!$HOME/bin/toffeebuild.sh"
endif
endfunction