From b8ffbf999555c72fa10aa9af3bca310ed3acf5c4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Tue, 17 Jul 2018 16:15:31 +1200 Subject: First version --- autoload/shebang_create_exec.vim | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 autoload/shebang_create_exec.vim (limited to 'autoload') 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 + \ 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 -- cgit v1.2.3