aboutsummaryrefslogtreecommitdiff
path: root/vim/ftplugin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-11-08 11:57:21 +1300
committerTom Ryder <tom@sanctum.geek.nz>2017-11-08 12:44:59 +1300
commitac577df9f6516308c2f9661c8abbc44f6c19d854 (patch)
tree5dbb56b651377ac9745d140491e01f6a47cc991f /vim/ftplugin
parent8a565011f7e4c04065f096a24f41c2d13234cf17 (diff)
downloaddotfiles-ac577df9f6516308c2f9661c8abbc44f6c19d854.tar.gz
dotfiles-ac577df9f6516308c2f9661c8abbc44f6c19d854.zip
Use sh.vim local vars not global POSIX hacks
Rather than setting g:is_posix and working around core syntax/sh.vim's ideas about Korn and POSIX shells, forego sh.vim's efforts to guess what shell the system /bin/sh is entirely. It's irrelevant to me anyway, since I'll often be writing shell scripts to run on an entirely different system. Instead, if we have a #!/bin/sh shebang reflected in the b:is_sh variable set by core filetype.vim, and we don't have any other buffer-level indication of what shell this is, assume it's POSIX, because I very rarely write Bourne. Then, after the syntax file is loaded, clear away all but one of the resulting b:is_* variables. I have a feeling this is going to end with me re-implementing this syntax file, possibly as separate sh.vim, bash.vim, and ksh.vim files.
Diffstat (limited to 'vim/ftplugin')
-rw-r--r--vim/ftplugin/sh.vim33
1 files changed, 14 insertions, 19 deletions
diff --git a/vim/ftplugin/sh.vim b/vim/ftplugin/sh.vim
index 21d494e3..7f453e92 100644
--- a/vim/ftplugin/sh.vim
+++ b/vim/ftplugin/sh.vim
@@ -1,23 +1,18 @@
-" Default to POSIX shell, as I never write Bourne, and if I write Bash or Ksh
-" it'll be denoted with either a shebang or an appropriate extension.
-let g:is_posix = 1
-
-"
-" Setting g:is_posix above also prompts Vim's core syntax/sh.vim script to
-" set g:is_kornshell and thereby b:is_kornshell to the same value as g:is_posix.
-"
-" That's very confusing, so before it happens we'll copy b:is_kornshell's
-" value as determined by filetype.vim and ~/.vim/ftdetect/sh.vim into a custom
-" variable b:is_ksh, before its meaning gets confused.
"
-" b:is_ksh as a name is more inline with b:is_bash and b:is_sh, anyway, so
-" we'll just treat b:is_kornshell like it's both misnamed and broken.
+" If we have a #!/bin/sh shebang and filetype.vim determined we were neither
+" POSIX nor Bash nor Korn shell, we'll guess POSIX, just because it's far more
+" likely that's what I want to write than plain Bourne shell.
"
-" We can then switch on our custom variable in ~/.vim/after/syntax/sh.vim to
-" apply settings that actually *are* unique to Korn shell and its derivatives.
+" You're supposed to be able to do this by setting g:is_posix, but if that's
+" set, the syntax file ends up setting g:is_kornshell for you too, for reasons
+" I don't really understand. This method works though, and is cleaner than
+" the other workaround I had been trying.
"
-if exists('b:is_kornshell')
- let b:is_ksh = b:is_kornshell
+if exists('b:is_sh')
+ unlet b:is_sh
+ if !exists('b:is_bash') && !exists('b:is_kornshell')
+ let b:is_posix = 1
+ endif
endif
" Use han(1df) as a man(1) wrapper for Bash files if available
@@ -30,7 +25,7 @@ endif
" Map checker based on shell family
if exists('b:is_bash') && b:is_bash
let b:check = 'write !bash -n'
-elseif exists('b:is_ksh') && b:is_ksh
+elseif exists('b:is_kornshell') && b:is_kornshell
let b:check = 'write !ksh -n'
else
let b:check = 'write !sh -n'
@@ -42,7 +37,7 @@ nnoremap <buffer> <silent>
" Map linter based on shell family
if exists('b:is_bash') && b:is_bash
let b:lint = 'write !shellcheck -s bash -'
-elseif exists('b:is_ksh') && b:is_ksh
+elseif exists('b:is_kornshell') && b:is_kornshell
let b:lint = 'write !shellcheck -s ksh -'
else
let b:lint = 'write !shellcheck -s sh -'