-
Notifications
You must be signed in to change notification settings - Fork 3
/
Hashbang
48 lines (37 loc) · 1013 Bytes
/
Hashbang
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
function! Hashbang(portable, permission, RemExt)
let shells = {
\ 'awk': "awk",
\ 'sh': "bash",
\ 'hs': "runhaskell",
\ 'jl': "julia",
\ 'lua': "lua",
\ 'mak': "make",
\ 'js': "node",
\ 'm': "octave",
\ 'pl': "perl",
\ 'php': "php",
\ 'py': "python",
\ 'r': "Rscript",
\ 'rb': "ruby",
\ 'scala': "scala",
\ 'tcl': "tclsh",
\ 'tk': "wish"
\ }
let extension = expand("%:e")
if has_key(shells,extension)
let fileshell = shells[extension]
if a:portable
let line = "#! /usr/bin/env " . fileshell
else
let line = "#! " . system("which " . fileshell)
endif
0put = line
if a:permission
:autocmd BufWritePost * :autocmd VimLeave * :!chmod u+x %
endif
if a:RemExt
:autocmd BufWritePost * :autocmd VimLeave * :!mv % "%:p:r"
endif
endif
endfunction
:autocmd BufNewFile *.* :call Hashbang(1,1,0)