aboutsummaryrefslogtreecommitdiff
path: root/vim/ftdetect/sh.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/ftdetect/sh.vim')
-rw-r--r--vim/ftdetect/sh.vim50
1 files changed, 43 insertions, 7 deletions
diff --git a/vim/ftdetect/sh.vim b/vim/ftdetect/sh.vim
index 880f08e9..1169b744 100644
--- a/vim/ftdetect/sh.vim
+++ b/vim/ftdetect/sh.vim
@@ -1,19 +1,55 @@
-" Add automatic commands to choose shell flavours based on filename pattern
+" Shell script files; these are hard to detect accurately
-" Names/paths of things that are Bash shell script
+" Bash filename patterns
autocmd BufNewFile,BufRead
- \ **/.dotfiles/bash/**,bash-fc-*
+ \ *.bash,
+ \.bash_aliases,
+ \.bash_logout,
+ \.bash_profile,
+ \.bashrc,
+ \bash-fc-*,
+ \bash_profile,
+ \bashrc
\ let b:is_bash = 1
\ | setfiletype sh
-" Names/paths of things that are Korn shell script
+" Korn shell filename patterns
autocmd BufNewFile,BufRead
- \ **/.dotfiles/ksh/**,.kshrc,*.ksh
+ \ *.ksh,
+ \.kshrc,
+ \kshrc
\ let b:is_kornshell = 1
\ | setfiletype sh
-" Names/paths of things that are POSIX shell script
+" POSIX/Bourne shell filename patterns
autocmd BufNewFile,BufRead
- \ **/.dotfiles/sh/**,.shinit,.shrc,.xinitrc,/etc/default/*
+ \ *.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) =~ '^#!.*bash$'
+ \ | let b:is_bash = 1
+ \ | setfiletype sh
+ \ | elseif getline(1) =~ '^#!.*ksh$'
+ \ | let b:is_ksh = 1
+ \ | setfiletype sh
+ \ | elseif getline(1) =~ '^#!.*sh$'
+ \ | let b:is_posix = 1
+ \ | setfiletype sh
+ \ | endif
+ \ | endif