1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
" Shell script files; these are hard to detect accurately
" Bash filename patterns
autocmd BufNewFile,BufRead
\ *.bash,
\.bash_aliases,
\.bash_logout,
\.bash_profile,
\.bashrc,
\bash-fc-*,
\bash_profile,
\bashrc
\ let b:is_bash = 1
\ | setfiletype sh
" Korn shell filename patterns
autocmd BufNewFile,BufRead
\ *.ksh,
\.kshrc,
\kshrc
\ let b:is_kornshell = 1
\ | setfiletype sh
" POSIX/Bourne shell filename patterns
autocmd BufNewFile,BufRead
\ *.sh,
\.profile,
\.shinit,
\.shrc,
\.xinitrc,
\/etc/default/*,
\configure,
\profile,
\shinit,
\shrc,
\xinitrc
\ let b:is_posix = 1
\ | setfiletype sh
" If this file has a shebang, and we haven't already decided it's Bash or
" Korn shell, use the shebang to decide
autocmd BufNewFile,BufRead
\ *
\ if !exists('b:is_bash') && !exists('b:is_kornshell')
\ | if getline(1) =~# '\m^#!.*\<bash\>'
\ | let b:is_bash = 1
\ | setfiletype sh
\ | elseif getline(1) =~# '\m^#!.*\<ksh\>'
\ | let b:is_ksh = 1
\ | setfiletype sh
\ | elseif getline(1) =~# '\m^#!.*\<sh\>'
\ | let b:is_posix = 1
\ | setfiletype sh
\ | endif
\ | endif
|