aboutsummaryrefslogtreecommitdiff
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
downloadvim-shebang-create-exec-0.1.0.tar.gz (sig)
vim-shebang-create-exec-0.1.0.zip
First versionv0.1.0
-rw-r--r--README.md0
-rw-r--r--VERSION1
-rw-r--r--autoload/shebang_create_exec.vim14
-rw-r--r--doc/shebang_create_exec.txt24
-rw-r--r--plugin/shebang_create_exec.vim21
5 files changed, 60 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README.md
diff --git a/VERSION b/VERSION
new file mode 100644
index 0000000..6e8bf73
--- /dev/null
+++ b/VERSION
@@ -0,0 +1 @@
+0.1.0
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
diff --git a/doc/shebang_create_exec.txt b/doc/shebang_create_exec.txt
new file mode 100644
index 0000000..1cf16be
--- /dev/null
+++ b/doc/shebang_create_exec.txt
@@ -0,0 +1,24 @@
+*shebang_create_exec.txt* For Vim version 7.1 Last change: 2018 July 17
+
+DESCRIPTION *shebang_create_exec*
+
+This plugin sets up a |BufWritePre| hook to check whether a buffer contains a
+Unix shebang like `#!/bin/sh` as the first line, and is being saved to a new
+file; if so, it attempts to make the file executable with `chmod +x` after a
+successful save.
+
+REQUIREMENTS *shebang_create_exec-requirements*
+
+This plugin only loads if 'compatible' is not set, and requires the |+autocmd|
+and |+unix| features. It also requires the |shellescape()| function that was
+added in |version-7.0| patch 111.
+
+AUTHOR *shebang_create_exec-author*
+
+Written and maintained by Tom Ryder <tom@sanctum.geek.nz>.
+
+LICENSE *shebang_create_exec-license*
+
+Licensed for distribution under the same terms as Vim itself (see |license|).
+
+ vim:tw=78:ts=8:ft=help:norl:
diff --git a/plugin/shebang_create_exec.vim b/plugin/shebang_create_exec.vim
new file mode 100644
index 0000000..401a23b
--- /dev/null
+++ b/plugin/shebang_create_exec.vim
@@ -0,0 +1,21 @@
+"
+" shebang_create_exec.vim: Make a file executable on first save if it starts with a
+" shebang.
+"
+" Author: Tom Ryder <tom@sanctum.geek.nz>
+" License: Same as Vim itself
+"
+if exists('g:loaded_shebang_create_exec') || &compatible
+ finish
+endif
+if !has('autocmd') || !has('unix') || !exists('*shellescape')
+ finish
+endif
+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 shebang_create_exec#Check(expand('<afile>:p'))
+augroup END