Make the shell detection better?

cat-town
Dan Buch 3 years ago
parent 6600e7b295
commit 5bfc637a7e
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

@ -11,7 +11,7 @@ let b:shell_name = "sh"
let b:load_time_cursor = getpos('.')
let b:debug = $JUST_VIM_DEBUG == 'enabled'
function JustGetShellName()
function! s:justGetShellName()
let lineno = 0
while lineno < line("$")
@ -31,35 +31,47 @@ function JustGetShellName()
echom "found matching line number " . lineno . ": " . line
endif
:normal /"<CR>lv/"<CR>hy:nohl
let shell_name = @"
:normal /"<CR>lv/"<CR>h"ay:nohl
let shell_name = @a
if shell_name != ""
if b:debug
echom "returning shell_name: '" . shell_name . "'"
endif
return shell_name
fi
endwhile
endif
endwhile
return "sh"
endfunc
try
let shell_name = JustGetShellName()
function! s:justSetShellName(shell_name)
try
if b:debug
echom "using shell name: '" . a:shell_name . "'"
endif
exe "syn include @setshellsyntax syntax/" . a:shell_name . ".vim"
if b:debug
echom "found shell name: '" . shell_name . "'"
endif
let b:shell_name = a:shell_name
catch
if b:debug
echom "oh no: " v:exception
echom "falling back to sh syntax"
endif
exe "syn include @setshellsyntax syntax/" . shell_name . ".vim"
syn include @setshellsyntax syntax/sh.vim
finally
syn region justSubshell matchgroup=justBacktick start=/\v\`/ skip=/\v\\\`/ end=/\v\`/ contains=@setshellsyntax
syn region justSubshell matchgroup=justBacktick start=/\v\`\`\`/ skip=/\v\\\`/ end=/\v\`\`\`/ contains=@setshellsyntax
endtry
endfunc
let b:shell_name = shell_name
catch
if b:debug
echom "oh no: " v:exception
echom "just.vim: falling back to sh syntax"
endif
call s:justSetShellName(s:justGetShellName())
syn include @setshellsyntax syntax/sh.vim
endtry
delfunc s:justSetShellName
delfunc s:justGetShellName
syn keyword justKeyword alias export if else set

Loading…
Cancel
Save