Skip to content

Commit 8224fc3

Browse files
committed
Add a new default sh interpreter template which guesses shell from shebang
Fix #69
1 parent 03fa60b commit 8224fc3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

autoload/SingleCompile.vim

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" Copyright (C) 2010-2014 Hong Xu
1+
" Copyright (C) 2010-2015 Hong Xu
22

33
" This file is part of SingleCompile.
44

@@ -401,6 +401,20 @@ function! SingleCompile#PredoMicrosoftVC(compiling_info) " MSVC Predo {{{2
401401
return l:new_compiling_info
402402
endfunction
403403

404+
function! SingleCompile#PredoShell(compiling_info) " shell predo {{{2
405+
let l:new_compiling_info = a:compiling_info
406+
407+
let l:shebang = getline(1)
408+
if l:shebang !~ '#!/.*' " don't change anything if no shebang is found
409+
return a:compiling_info
410+
endif
411+
412+
" Use the shell indicated by the shebang
413+
let l:new_compiling_info['command'] = matchstr(l:shebang, '#!\zs/.*')
414+
415+
return l:new_compiling_info
416+
endfunction
417+
404418
" post-do functions {{{1
405419
function! SingleCompile#PostdoWatcom(compiling_info) " watcom pre-do {{{2
406420
let $PATH = s:old_path

autoload/SingleCompile/templates/sh.vim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
" Copyright (C) 2010-2012 Hong Xu
1+
" Copyright (C) 2010-2015 Hong Xu
22

33
" This file is part of SingleCompile.
44

@@ -18,6 +18,11 @@
1818
" check doc/SingleCompile.txt for more information
1919

2020
function! SingleCompile#templates#sh#Initialize()
21+
call SingleCompile#SetCompilerTemplate('sh', 'shell',
22+
\'Guess from shebang', 'sh', '', '')
23+
call SingleCompile#SetPriority('sh', 'shell', 10)
24+
call SingleCompile#SetPredo('sh', 'shell',
25+
\function('SingleCompile#PredoShell'))
2126
call SingleCompile#SetCompilerTemplate('sh', 'sh',
2227
\'Bourne Shell', 'sh', '', '')
2328
call SingleCompile#SetPriority('sh', 'sh', 80)

0 commit comments

Comments
 (0)