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: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
if b:debug
echom "found shell name: '" . shell_name . "'"
endif
exe "syn include @setshellsyntax syntax/" . a:shell_name . ".vim"
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
catch
if b:debug
echom "oh no: " v:exception
echom "just.vim: falling back to sh syntax"
endif
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
syn include @setshellsyntax syntax/sh.vim
endtry
call s:justSetShellName(s:justGetShellName())
delfunc s:justSetShellName
delfunc s:justGetShellName
syn keyword justKeyword alias export if else set