aboutsummaryrefslogtreecommitdiff
path: root/vim/autoload/shebang_create_exec.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-17 16:08:22 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-17 16:08:22 +1200
commit3155b55819b5af8f6186b597331c04c94eaf93db (patch)
treefe99c6cd3d6c67ac603145a8dd5625cf99e8898c /vim/autoload/shebang_create_exec.vim
parentMerge branch 'release/v1.33.0' into develop (diff)
downloaddotfiles-3155b55819b5af8f6186b597331c04c94eaf93db.tar.gz
dotfiles-3155b55819b5af8f6186b597331c04c94eaf93db.zip
Separate shebang_create_exec into autoload funcs
Diffstat (limited to 'vim/autoload/shebang_create_exec.vim')
-rw-r--r--vim/autoload/shebang_create_exec.vim14
1 files changed, 14 insertions, 0 deletions
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 <buffer>
+ \ call shebang_create_exec#Chmod(expand('<afile>: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 <buffer>
+ call system('chmod +x '.shellescape(a:filename))
+endfunction