sh.vim 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. "============================================================================
  2. "File: sh.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Gregor Uhlenheuer <kongo2002 at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. "============================================================================
  12. if exists('g:loaded_syntastic_sh_sh_checker')
  13. finish
  14. endif
  15. let g:loaded_syntastic_sh_sh_checker = 1
  16. let s:save_cpo = &cpo
  17. set cpo&vim
  18. function! SyntaxCheckers_sh_sh_IsAvailable() dict " {{{1
  19. call self.log('shell =', s:GetShell())
  20. return s:IsShellValid()
  21. endfunction " }}}1
  22. function! SyntaxCheckers_sh_sh_GetLocList() dict " {{{1
  23. if s:GetShell() ==# 'zsh'
  24. return s:ForwardToZshChecker()
  25. endif
  26. if !s:IsShellValid()
  27. return []
  28. endif
  29. let makeprg = self.makeprgBuild({
  30. \ 'exe': s:GetShell(),
  31. \ 'args_after': '-n' })
  32. let errorformat = '%f: line %l: %m'
  33. return SyntasticMake({
  34. \ 'makeprg': makeprg,
  35. \ 'errorformat': errorformat })
  36. endfunction " }}}1
  37. " Utilities {{{1
  38. function! s:GetShell() " {{{2
  39. if !exists('b:shell') || b:shell ==# ''
  40. let b:shell = ''
  41. let shebang = syntastic#util#parseShebang()['exe']
  42. if shebang !=# ''
  43. if shebang[-strlen('bash'):-1] ==# 'bash'
  44. let b:shell = 'bash'
  45. elseif shebang[-strlen('zsh'):-1] ==# 'zsh'
  46. let b:shell = 'zsh'
  47. elseif shebang[-strlen('sh'):-1] ==# 'sh'
  48. let b:shell = 'sh'
  49. endif
  50. endif
  51. " try to use env variable in case no shebang could be found
  52. if b:shell ==# ''
  53. let b:shell = fnamemodify($SHELL, ':t')
  54. endif
  55. endif
  56. return b:shell
  57. endfunction " }}}2
  58. function! s:IsShellValid() " {{{2
  59. let shell = s:GetShell()
  60. return shell !=# '' && executable(shell)
  61. endfunction " }}}2
  62. function! s:ForwardToZshChecker() " {{{2
  63. let registry = g:SyntasticRegistry.Instance()
  64. let zsh_checkers = registry.getCheckersAvailable('zsh', ['zsh'])
  65. if !empty(zsh_checkers)
  66. return zsh_checkers[0].getLocListRaw()
  67. else
  68. return []
  69. endif
  70. endfunction " }}}2
  71. " }}}1
  72. call g:SyntasticRegistry.CreateAndRegisterChecker({
  73. \ 'filetype': 'sh',
  74. \ 'name': 'sh' })
  75. let &cpo = s:save_cpo
  76. unlet s:save_cpo
  77. " vim: set sw=4 sts=4 et fdm=marker: