Make the shell detection better?

This commit is contained in:
Dan Buch 2021-05-23 20:43:59 -04:00
parent 6600e7b295
commit 5bfc637a7e
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

View File

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