From 3155b55819b5af8f6186b597331c04c94eaf93db Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 17 Jul 2018 16:08:22 +1200 Subject: Separate shebang_create_exec into autoload funcs --- vim/autoload/shebang_create_exec.vim | 14 ++++++++++++++ vim/plugin/shebang_create_exec.vim | 18 ++---------------- 2 files changed, 16 insertions(+), 16 deletions(-) create mode 100644 vim/autoload/shebang_create_exec.vim (limited to 'vim') diff --git a/vim/autoload/shebang_create_exec.vim b/vim/autoload/shebang_create_exec.vim new file mode 100644 index 00000000..b01cf584 --- /dev/null +++ b/vim/autoload/shebang_create_exec.vim @@ -0,0 +1,14 @@ +" If the buffer starts with a shebang and the file being saved to doesn't +" exist yet, set up a hook to make it executable after the write is done +function! shebang_create_exec#Check(filename) abort + if stridx(getline(1), '#!') == 0 && !filereadable(a:filename) + autocmd shebang_create_exec BufWritePost + \ call shebang_create_exec#Chmod(expand(':p')) + endif +endfunction + +" Make the file executable and clear away the hook that called us +function! shebang_create_exec#Chmod(filename) abort + autocmd! shebang_create_exec BufWritePost + call system('chmod +x '.shellescape(a:filename)) +endfunction diff --git a/vim/plugin/shebang_create_exec.vim b/vim/plugin/shebang_create_exec.vim index 7fabd8f7..401a23b8 100644 --- a/vim/plugin/shebang_create_exec.vim +++ b/vim/plugin/shebang_create_exec.vim @@ -16,20 +16,6 @@ let g:loaded_shebang_create_exec = 1 " Set up hook for before writes to check the buffer for new shebangs augroup shebang_create_exec autocmd! - autocmd BufWritePre * call s:Check(expand(':p')) + autocmd BufWritePre * + \ call shebang_create_exec#Check(expand(':p')) augroup END - -" If the buffer starts with a shebang and the file being saved to doesn't -" exist yet, set up a hook to make it executable after the write is done -function! s:Check(filename) abort - if stridx(getline(1), '#!') == 0 && !filereadable(a:filename) - autocmd shebang_create_exec BufWritePost - \ call s:Chmod(expand(':p')) - endif -endfunction - -" Make the file executable and clear away the hook that called us -function! s:Chmod(filename) abort - autocmd! shebang_create_exec BufWritePost - call system('chmod +x '.shellescape(a:filename)) -endfunction -- cgit v1.2.3