]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/handlers/sh.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / handlers / sh.vim
1 " Author: w0rp <devw0rp@gmail.com>
2
3 function! ale#handlers#sh#GetShellType(buffer) abort
4     let l:shebang = get(getbufline(a:buffer, 1), 0, '')
5
6     let l:command = ''
7
8     " Take the shell executable from the shebang, if we can.
9     if l:shebang[:1] is# '#!'
10         " Remove options like -e, etc.
11         let l:command = substitute(l:shebang, ' --\?[a-zA-Z0-9]\+', '', 'g')
12     endif
13
14     " With no shebang line, attempt to use Vim's buffer-local variables.
15     if l:command is# ''
16         if getbufvar(a:buffer, 'is_bash', 0)
17             let l:command = 'bash'
18         elseif getbufvar(a:buffer, 'is_sh', 0)
19             let l:command = 'sh'
20         elseif getbufvar(a:buffer, 'is_kornshell', 0)
21             let l:command = 'ksh'
22         endif
23     endif
24
25     " If we couldn't find a shebang, try the filetype
26     if l:command is# ''
27         let l:command = &filetype
28     endif
29
30     for l:possible_shell in ['bash', 'dash', 'ash', 'tcsh', 'csh', 'zsh', 'ksh', 'sh']
31         if l:command =~# l:possible_shell . '\s*$'
32             return l:possible_shell
33         endif
34     endfor
35
36     return ''
37 endfunction