aboutsummaryrefslogtreecommitdiff
path: root/vim/ftdetect/sh.vim
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-06-03 12:52:27 +1200
committerTom Ryder <tom@sanctum.geek.nz>2018-06-03 12:52:27 +1200
commitb16ddff69d781143f210c3c629be27c9e68f5626 (patch)
tree4d068fd14280daf5f26fa44eb7e8629ed0a274d7 /vim/ftdetect/sh.vim
parentMerge branch 'release/v0.42.0' (diff)
parentBump VERSION (diff)
downloaddotfiles-b16ddff69d781143f210c3c629be27c9e68f5626.tar.gz
dotfiles-b16ddff69d781143f210c3c629be27c9e68f5626.zip
Merge branch 'release/v0.43.0'v0.43.0
* release/v0.43.0: Bump VERSION Revamp vint script with blacklist not whitelist Add missing vint targets Add shebang and opening tag detect for PHP Refine shebangs in filetype detection Implement personal filetype.vim Correct name of Makefile target Refactor Vim distribution plugin/macro handling Rebuild help tags after installing bundle Use full commands in buffer cycle mappings Upgrade mail_mutt.vim plugin to v0.2.0
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..1427bc03 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) =~# '\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