aboutsummaryrefslogtreecommitdiff
path: root/autoload/shebang_create_exec.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-07-17 16:15:31 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-07-17 16:15:31 +1200
commitb8ffbf999555c72fa10aa9af3bca310ed3acf5c4 (patch)
tree621298221f15797a31cc3129506805c62b05c7ab /autoload/shebang_create_exec.vim
downloadvim-shebang-create-exec-0.1.0.tar.gz (sig)
vim-shebang-create-exec-0.1.0.zip
First versionv0.1.0
Diffstat (limited to 'autoload/shebang_create_exec.vim')
-rw-r--r--autoload/shebang_create_exec.vim14
1 files changed, 14 insertions, 0 deletions
diff --git a/autoload/shebang_create_exec.vim b/autoload/shebang_create_exec.vim
new file mode 100644
index 0000000..b01cf58
--- /dev/null
+++ b/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