├── .gitignore ├── Makefile ├── README.md ├── indent └── sh.vim ├── test ├── 10 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 11 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 12 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 13 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 14 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 15 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 16 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 17 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 18 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 19 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 20 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 21 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 22 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 01 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 02 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 03 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 05 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 06 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 07 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 08 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── 09 │ ├── cmd.sh │ ├── indent.sh │ └── reference.sh ├── indent1.sh └── test.sh └── vim-sh-indent.zip /.gitignore: -------------------------------------------------------------------------------- 1 | /test/*/output.sh 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PLUGIN=$(shell basename "$$PWD") 2 | .PHONY: test 3 | 4 | test: 5 | cd test && ./test.sh -v && cd .. && echo "cleaning output" && $(MAKE) clean > /dev/null 6 | 7 | zip: 8 | @rm -f $(PLUGIN).zip; find . -type f -name "*.vim" | zip -@ $(PLUGIN).zip 9 | 10 | clean: 11 | find . -type f -name "output.sh" -delete -o -name "*.swp" -delete 12 | 13 | submit: 14 | @echo "Set environment variable '\$$MSG' to the tag message, like this:" 15 | @echo "MSG='My tag message'" 16 | @echo "git tag -f -s \`date +'%Y%m%d'\` -m \"\$$MSG\"" 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-sh-indent [![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/chrisbra) 2 | Official Vim indent script for the shell. 3 | 4 | # License 5 | The Vim License applies. See `:h license` 6 | -------------------------------------------------------------------------------- /indent/sh.vim: -------------------------------------------------------------------------------- 1 | " Vim indent file 2 | " Language: Shell Script 3 | " Maintainer: Christian Brabandt 4 | " Original Author: Nikolai Weibull 5 | " Previous Maintainer: Peter Aronoff 6 | " Latest Revision: 2019-10-24 7 | " License: Vim (see :h license) 8 | " Repository: https://github.com/chrisbra/vim-sh-indent 9 | " Changelog: 10 | " 20250318 - Detect local arrays in functions 11 | " 20241411 - Detect dash character in function keyword for 12 | " bash mode (issue #16049) 13 | " 20190726 - Correctly skip if keywords in syntax comments 14 | " (issue #17) 15 | " 20190603 - Do not indent in zsh filetypes with an `if` in comments 16 | " 20190428 - De-indent fi correctly when typing with 17 | " https://github.com/chrisbra/vim-sh-indent/issues/15 18 | " 20190325 - Indent fi; correctly 19 | " https://github.com/chrisbra/vim-sh-indent/issues/14 20 | " 20190319 - Indent arrays (only zsh and bash) 21 | " https://github.com/chrisbra/vim-sh-indent/issues/13 22 | " 20190316 - Make use of searchpairpos for nested if sections 23 | " fixes https://github.com/chrisbra/vim-sh-indent/issues/11 24 | " 20190201 - Better check for closing if sections 25 | " 20180724 - make check for zsh syntax more rigid (needs word-boundaries) 26 | " 20180326 - better support for line continuation 27 | " 20180325 - better detection of function definitions 28 | " 20180127 - better support for zsh complex commands 29 | " 20170808: - better indent of line continuation 30 | " 20170502: - get rid of buffer-shiftwidth function 31 | " 20160912: - preserve indentation of here-doc blocks 32 | " 20160627: - detect heredocs correctly 33 | " 20160213: - detect function definition correctly 34 | " 20160202: - use shiftwidth() function 35 | " 20151215: - set b:undo_indent variable 36 | " 20150728: - add foreach detection for zsh 37 | 38 | if exists("b:did_indent") 39 | finish 40 | endif 41 | let b:did_indent = 1 42 | 43 | setlocal indentexpr=GetShIndent() 44 | setlocal indentkeys+=0=then,0=do,0=else,0=elif,0=fi,0=esac,0=done,0=end,),0=;;,0=;& 45 | setlocal indentkeys+=0=fin,0=fil,0=fip,0=fir,0=fix 46 | setlocal indentkeys-=:,0# 47 | setlocal nosmartindent 48 | 49 | let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent<' 50 | 51 | if exists("*GetShIndent") 52 | finish 53 | endif 54 | 55 | let s:cpo_save = &cpo 56 | set cpo&vim 57 | 58 | let s:sh_indent_defaults = { 59 | \ 'default': function('shiftwidth'), 60 | \ 'continuation-line': function('shiftwidth'), 61 | \ 'case-labels': function('shiftwidth'), 62 | \ 'case-statements': function('shiftwidth'), 63 | \ 'case-breaks': 0 } 64 | 65 | function! s:indent_value(option) 66 | let Value = exists('b:sh_indent_options') 67 | \ && has_key(b:sh_indent_options, a:option) ? 68 | \ b:sh_indent_options[a:option] : 69 | \ s:sh_indent_defaults[a:option] 70 | if type(Value) == type(function('type')) 71 | return Value() 72 | endif 73 | return Value 74 | endfunction 75 | 76 | function! GetShIndent() 77 | let mode = mode() 78 | 79 | let curline = getline(v:lnum) 80 | let lnum = prevnonblank(v:lnum - 1) 81 | if lnum == 0 82 | return 0 83 | endif 84 | let line = getline(lnum) 85 | 86 | let pnum = prevnonblank(lnum - 1) 87 | let pline = getline(pnum) 88 | let ind = indent(lnum) 89 | 90 | " Check contents of previous lines 91 | " should not apply to e.g. commented lines 92 | 93 | if s:start_block(line) 94 | let ind += s:indent_value('default') 95 | elseif line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>\($\|\s\)' || 96 | \ (&ft is# 'zsh' && line =~ '^\s*\<\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>\($\|\s\)') 97 | if !s:is_end_expression(line) 98 | let ind += s:indent_value('default') 99 | endif 100 | elseif s:is_case_label(line, pnum) 101 | if !s:is_case_ended(line) 102 | let ind += s:indent_value('case-statements') 103 | endif 104 | " function definition 105 | elseif s:is_function_definition(line) 106 | if line !~ '}\s*\%(#.*\)\=$' 107 | let ind += s:indent_value('default') 108 | endif 109 | " array (only works for zsh or bash) 110 | elseif s:is_array(line) && line !~ ')\s*$' && (&ft is# 'zsh' || s:is_bash()) 111 | let ind += s:indent_value('continuation-line') 112 | " end of array 113 | elseif curline =~ '^\s*)$' 114 | let ind -= s:indent_value('continuation-line') 115 | elseif s:is_continuation_line(line) 116 | if pnum == 0 || !s:is_continuation_line(pline) 117 | let ind += s:indent_value('continuation-line') 118 | endif 119 | elseif s:end_block(line) && !s:start_block(line) 120 | let ind -= s:indent_value('default') 121 | elseif pnum != 0 && 122 | \ s:is_continuation_line(pline) && 123 | \ !s:end_block(curline) && 124 | \ !s:is_end_expression(curline) 125 | " only add indent, if line and pline is in the same block 126 | let i = v:lnum 127 | let ind2 = indent(s:find_continued_lnum(pnum)) 128 | while !s:is_empty(getline(i)) && i > pnum 129 | let i -= 1 130 | endw 131 | if i == pnum && (s:is_continuation_line(line) || pline =~ '{\s*\(#.*\)\=$') 132 | let ind += ind2 133 | else 134 | let ind = ind2 135 | endif 136 | endif 137 | 138 | let pine = line 139 | " Check content of current line 140 | let line = curline 141 | " Current line is a endif line, so get indent from start of "if condition" line 142 | " TODO: should we do the same for other "end" lines? 143 | if curline =~ '^\s*\%(fi\);\?\s*\%(#.*\)\=$' 144 | let ind = indent(v:lnum) 145 | " in insert mode, try to place the cursor after the fi statement 146 | let endp = '\' .. (mode ==? 'i' ? '\zs' : '') 147 | let startp = '^\s*\' 148 | let previous_line = searchpair(startp, '', endp , 'bnW', 149 | \ 'synIDattr(synID(line("."),col("."), 1),"name") =~? "comment\\|quote\\|option"') 150 | if previous_line > 0 151 | let ind = indent(previous_line) 152 | endif 153 | elseif line =~ '^\s*\%(then\|do\|else\|elif\|done\|end\)\>' || s:end_block(line) 154 | let ind -= s:indent_value('default') 155 | elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1)) 156 | let ind -= s:indent_value('default') 157 | elseif line =~ '^\s*esac\>' 158 | let ind -= (s:is_case_label(pine, lnum) && s:is_case_ended(pine) ? 159 | \ 0 : s:indent_value('case-statements')) + 160 | \ s:indent_value('case-labels') 161 | if s:is_case_break(pine) 162 | let ind += s:indent_value('case-breaks') 163 | endif 164 | elseif s:is_case_label(line, lnum) 165 | if s:is_case(pine) 166 | let ind = indent(lnum) + s:indent_value('case-labels') 167 | else 168 | let ind -= (s:is_case_label(pine, lnum) && s:is_case_ended(pine) ? 169 | \ 0 : s:indent_value('case-statements')) - 170 | \ s:indent_value('case-breaks') 171 | endif 172 | elseif s:is_case_break(line) 173 | let ind -= s:indent_value('case-breaks') 174 | elseif s:is_here_doc(line) 175 | let ind = 0 176 | " statements, executed within a here document. Keep the current indent 177 | elseif match(map(synstack(v:lnum, 1), 'synIDattr(v:val, "name")'), '\c\mheredoc') > -1 178 | return indent(v:lnum) 179 | elseif s:is_comment(line) && s:is_empty(getline(v:lnum-1)) 180 | if s:is_in_block(v:lnum) 181 | " return indent of line in same block 182 | return indent(lnum) 183 | else 184 | " use indent of current line 185 | return indent(v:lnum) 186 | endif 187 | endif 188 | 189 | return ind > 0 ? ind : 0 190 | endfunction 191 | 192 | function! s:is_continuation_line(line) 193 | " Comment, cannot be a line continuation 194 | if a:line =~ '^\s*#' 195 | return 0 196 | else 197 | " start-of-line 198 | " \\ or && or || or | 199 | " followed optionally by { or # 200 | return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' . 201 | \ '\s*\({\s*\)\=\(#.*\)\=$' 202 | endif 203 | endfunction 204 | 205 | function! s:find_continued_lnum(lnum) 206 | let i = a:lnum 207 | while i > 1 && s:is_continuation_line(getline(i - 1)) 208 | let i -= 1 209 | endwhile 210 | return i 211 | endfunction 212 | 213 | function! s:is_function_definition(line) 214 | return a:line =~ '^\s*\<\k\+\>\s*()\s*{' || 215 | \ a:line =~ '^\s*{' || 216 | \ a:line =~ '^\s*function\s*\k\+\s*\%(()\)\?\s*{' || 217 | \ ((&ft is# 'zsh' || s:is_bash()) && 218 | \ a:line =~ '^\s*function\s*\S\+\s*\%(()\)\?\s*{' ) 219 | endfunction 220 | 221 | function! s:is_array(line) 222 | return a:line =~ '^\s*\(\(declare\|typeset\|local\)\s\+\(-[Aalrtu]\+\s\+\)\?\)\?\<\k\+\>=(' 223 | endfunction 224 | 225 | function! s:is_in_block(line) 226 | " checks whether a:line is whithin a 227 | " block e.g. a shell function 228 | " foo() { 229 | " .. 230 | " } 231 | let prevline = searchpair('{', '', '}', 'bnW', 'synIDattr(synID(line("."),col("."), 1),"name") =~? "comment\\|quote"') 232 | let nextline = searchpair('{', '', '}', 'nW', 'synIDattr(synID(line("."),col("."), 1),"name") =~? "comment\\|quote"') 233 | return a:line > prevline && a:line < nextline 234 | endfunction 235 | 236 | function! s:is_case_label(line, pnum) 237 | if a:line !~ '^\s*(\=.*)' 238 | return 0 239 | endif 240 | 241 | if a:pnum > 0 242 | let pine = getline(a:pnum) 243 | if !(s:is_case(pine) || s:is_case_ended(pine)) 244 | return 0 245 | endif 246 | endif 247 | 248 | let suffix = substitute(a:line, '^\s*(\=', "", "") 249 | let nesting = 0 250 | let i = 0 251 | let n = strlen(suffix) 252 | while i < n 253 | let c = suffix[i] 254 | let i += 1 255 | if c == '\\' 256 | let i += 1 257 | elseif c == '(' 258 | let nesting += 1 259 | elseif c == ')' 260 | if nesting == 0 261 | return 1 262 | endif 263 | let nesting -= 1 264 | endif 265 | endwhile 266 | return 0 267 | endfunction 268 | 269 | function! s:is_case(line) 270 | return a:line =~ '^\s*case\>' 271 | endfunction 272 | 273 | function! s:is_case_break(line) 274 | return a:line =~ '^\s*;[;&]' 275 | endfunction 276 | 277 | function! s:is_here_doc(line) 278 | if a:line =~ '^\w\+$' 279 | let here_pat = '<<-\?'. s:escape(a:line). '\$' 280 | return search(here_pat, 'bnW') > 0 281 | endif 282 | return 0 283 | endfunction 284 | 285 | function! s:is_case_ended(line) 286 | return s:is_case_break(a:line) || a:line =~ ';[;&]\s*\%(#.*\)\=$' 287 | endfunction 288 | 289 | function! s:is_case_empty(line) 290 | if a:line =~ '^\s*$' || a:line =~ '^\s*#' 291 | return s:is_case_empty(getline(v:lnum - 1)) 292 | else 293 | return a:line =~ '^\s*case\>' 294 | endif 295 | endfunction 296 | 297 | function! s:escape(pattern) 298 | return '\V'. escape(a:pattern, '\\') 299 | endfunction 300 | 301 | function! s:is_empty(line) 302 | return a:line =~ '^\s*$' 303 | endfunction 304 | 305 | function! s:end_block(line) 306 | return a:line =~ '^\s*}' 307 | endfunction 308 | 309 | function! s:start_block(line) 310 | # return a:line =~ '{\s*\(#.*\)\?$' 311 | return a:line =~ '^[^#]*[{(]\s*\(#.*\)\?$' 312 | endfunction 313 | 314 | function! s:is_comment(line) 315 | return a:line =~ '^\s*#' 316 | endfunction 317 | 318 | function! s:is_end_expression(line) 319 | return a:line =~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$' 320 | endfunction 321 | 322 | function! s:is_bash() 323 | if &ft is# 'bash' || getline(1) is# '#!/bin/bash' 324 | return v:true 325 | else 326 | return get(g:, 'is_bash', 0) || get(b:, 'is_bash', 0) 327 | endif 328 | endfunction 329 | 330 | let &cpo = s:cpo_save 331 | unlet s:cpo_save 332 | -------------------------------------------------------------------------------- /test/01/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/01/indent.sh: -------------------------------------------------------------------------------- 1 | # load this file, set ft=sh, gg=G 2 | # should show the same indentation as indent.sh.expected 3 | # with sw=0 sts=-1 and ts=2 4 | 5 | var=${true:-5} 6 | 7 | #var=${true:-5} 8 | #echo hi 9 | 10 | echo << EOF 11 | hi there { 12 | more { 13 | EOF 14 | 15 | #{ 16 | 17 | echo 'test # most evil {' 18 | echo hi 19 | 20 | echo true # evil { 21 | echo hi 22 | 23 | #function hello { 24 | # echo hi 25 | #} 26 | 27 | var=${true:-5} 28 | 29 | function hello { 30 | echo hi 31 | } 32 | echo hi 33 | 34 | most_fun() { echo hi; 35 | echo hi 36 | } 37 | 38 | hi() { echo hi && 39 | echo hi 40 | } 41 | 42 | fun() { true; } 43 | 44 | more_fun() { # test 45 | echo test 46 | } 47 | 48 | test_this () { 49 | echo hi 50 | } 51 | 52 | fun() { # test 53 | echo test 54 | } 55 | 56 | # echo hi && 57 | # there 58 | 59 | #{ true; true; false } | 60 | # true 61 | 62 | echo hi 63 | 64 | { # test 65 | echo test 66 | } 67 | 68 | true && { 69 | echo test 70 | } 71 | 72 | true && { # test 73 | echo test 74 | } 75 | 76 | true && { echo test; } 77 | echo hi 78 | 79 | most_fun 80 | 81 | echo pipes | # true 82 | echo pipend 83 | 84 | true && # hi! 85 | echo inside 86 | 87 | true && # hello \ 88 | echo inside 89 | 90 | true && 91 | echo ok || 92 | echo not ok 93 | 94 | cd build || { 95 | echo "Failed to move to build directory" 96 | exit 1 97 | } 98 | 99 | echo this example below works 100 | [[ true ]] && { 101 | : 102 | } || { 103 | : 104 | } 105 | echo 'this line should not be indented' 106 | 107 | echo this example below NOT works 108 | [[ true ]] && 109 | { 110 | : 111 | } || { 112 | : 113 | } 114 | echo 'this line should not be indented' 115 | 116 | echo this example below NOT works 117 | [[ true ]] && 118 | { 119 | : 120 | } || { 121 | : 122 | } 123 | echo 'this line should not be indented' 124 | 125 | echo this example below NOT works 126 | [[ true ]] && 127 | { 128 | : 129 | } || 130 | { 131 | : 132 | } 133 | echo 'this line should not be indented' 134 | 135 | # Should be indented correctly 136 | if true; then 137 | echo 'pipe beginning' | 138 | sed 's/beginn/end/' 139 | fi 140 | 141 | # vim:sw=0:sts=-1:ts=2 142 | -------------------------------------------------------------------------------- /test/01/reference.sh: -------------------------------------------------------------------------------- 1 | # load this file, set ft=sh, gg=G 2 | # should show the same indentation as indent.sh.expected 3 | # with sw=0 sts=-1 and ts=2 4 | 5 | var=${true:-5} 6 | 7 | #var=${true:-5} 8 | #echo hi 9 | 10 | echo << EOF 11 | hi there { 12 | more { 13 | EOF 14 | 15 | #{ 16 | 17 | echo 'test # most evil {' 18 | echo hi 19 | 20 | echo true # evil { 21 | echo hi 22 | 23 | #function hello { 24 | # echo hi 25 | #} 26 | 27 | var=${true:-5} 28 | 29 | function hello { 30 | echo hi 31 | } 32 | echo hi 33 | 34 | most_fun() { echo hi; 35 | echo hi 36 | } 37 | 38 | hi() { echo hi && 39 | echo hi 40 | } 41 | 42 | fun() { true; } 43 | 44 | more_fun() { # test 45 | echo test 46 | } 47 | 48 | test_this () { 49 | echo hi 50 | } 51 | 52 | fun() { # test 53 | echo test 54 | } 55 | 56 | # echo hi && 57 | # there 58 | 59 | #{ true; true; false } | 60 | # true 61 | 62 | echo hi 63 | 64 | { # test 65 | echo test 66 | } 67 | 68 | true && { 69 | echo test 70 | } 71 | 72 | true && { # test 73 | echo test 74 | } 75 | 76 | true && { echo test; } 77 | echo hi 78 | 79 | most_fun 80 | 81 | echo pipes | # true 82 | echo pipend 83 | 84 | true && # hi! 85 | echo inside 86 | 87 | true && # hello \ 88 | echo inside 89 | 90 | true && 91 | echo ok || 92 | echo not ok 93 | 94 | cd build || { 95 | echo "Failed to move to build directory" 96 | exit 1 97 | } 98 | 99 | echo this example below works 100 | [[ true ]] && { 101 | : 102 | } || { 103 | : 104 | } 105 | echo 'this line should not be indented' 106 | 107 | echo this example below NOT works 108 | [[ true ]] && 109 | { 110 | : 111 | } || { 112 | : 113 | } 114 | echo 'this line should not be indented' 115 | 116 | echo this example below NOT works 117 | [[ true ]] && 118 | { 119 | : 120 | } || { 121 | : 122 | } 123 | echo 'this line should not be indented' 124 | 125 | echo this example below NOT works 126 | [[ true ]] && 127 | { 128 | : 129 | } || 130 | { 131 | : 132 | } 133 | echo 'this line should not be indented' 134 | 135 | # Should be indented correctly 136 | if true; then 137 | echo 'pipe beginning' | 138 | sed 's/beginn/end/' 139 | fi 140 | 141 | # vim:sw=0:sts=-1:ts=2 142 | -------------------------------------------------------------------------------- /test/02/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/02/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [[ /bin/true ]]; then 4 | echo "true" 5 | else 6 | echo "false" 7 | if [[ /bin/false ]]; then 8 | echo "false" 9 | else 10 | echo "true" 11 | fi 12 | fi 13 | if [[ /bin/true ]] 14 | then 15 | echo "true" 16 | else 17 | echo "false" 18 | if [[ /bin/false ]] 19 | then 20 | echo "false" 21 | else 22 | echo "true" 23 | fi 24 | fi 25 | -------------------------------------------------------------------------------- /test/02/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if [[ /bin/true ]]; then 4 | echo "true" 5 | else 6 | echo "false" 7 | if [[ /bin/false ]]; then 8 | echo "false" 9 | else 10 | echo "true" 11 | fi 12 | fi 13 | if [[ /bin/true ]] 14 | then 15 | echo "true" 16 | else 17 | echo "false" 18 | if [[ /bin/false ]] 19 | then 20 | echo "false" 21 | else 22 | echo "true" 23 | fi 24 | fi 25 | -------------------------------------------------------------------------------- /test/03/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/03/indent.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | if true; then 4 | echo 'pipe beginning' 5 | sed 's/beginn/end/' 6 | fi 7 | 8 | # TODO: 9 | # The line after the pipe will be indented. Is this correct? 10 | if true; then 11 | echo 'pipe beginning' | 12 | sed 's/beginn/end/' 13 | fi 14 | -------------------------------------------------------------------------------- /test/03/reference.sh: -------------------------------------------------------------------------------- 1 | #/bin/sh 2 | 3 | if true; then 4 | echo 'pipe beginning' 5 | sed 's/beginn/end/' 6 | fi 7 | 8 | # TODO: 9 | # The line after the pipe will be indented. Is this correct? 10 | if true; then 11 | echo 'pipe beginning' | 12 | sed 's/beginn/end/' 13 | fi 14 | -------------------------------------------------------------------------------- /test/05/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c ':let g:is_bash=1' \ 9 | -c 'norm! gg=G' \ 10 | -c ':saveas! output.sh' \ 11 | -c ':q!' indent.sh 12 | -------------------------------------------------------------------------------- /test/05/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DOTFILES=( 4 | ".bashrc" 5 | ".bash_profile" 6 | ".gitconfig" 7 | ".profile" 8 | ) 9 | 10 | if true; then 11 | echo 'pipe beginning' 12 | sed 's/beginn/end/' 13 | fi 14 | -------------------------------------------------------------------------------- /test/05/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | DOTFILES=( 4 | ".bashrc" 5 | ".bash_profile" 6 | ".gitconfig" 7 | ".profile" 8 | ) 9 | 10 | if true; then 11 | echo 'pipe beginning' 12 | sed 's/beginn/end/' 13 | fi 14 | -------------------------------------------------------------------------------- /test/06/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c ':let g:is_bash=1' \ 9 | -c 'norm! gg=G' \ 10 | -c ':saveas! output.sh' \ 11 | -c ':q!' indent.sh 12 | -------------------------------------------------------------------------------- /test/06/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Test: 3 | # Indentation should work for if/fi sections with or without trailing ';' 4 | if [ "$1" == "test" ]; 5 | then 6 | echo "$1"; 7 | fi 8 | if [ "$1" == "1" ]; 9 | then 10 | echo "test"; 11 | fi; 12 | if [ "$2" == "2" ]; 13 | then 14 | echo "test"; 15 | fi; 16 | -------------------------------------------------------------------------------- /test/06/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Test: 3 | # Indentation should work for if/fi sections with or without trailing ';' 4 | if [ "$1" == "test" ]; 5 | then 6 | echo "$1"; 7 | fi 8 | if [ "$1" == "1" ]; 9 | then 10 | echo "test"; 11 | fi; 12 | if [ "$2" == "2" ]; 13 | then 14 | echo "test"; 15 | fi; 16 | -------------------------------------------------------------------------------- /test/07/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c ':5' \ 9 | -c 'norm! ciwfi' \ 10 | -c ':saveas! output.sh' \ 11 | -c ':q!' indent.sh 12 | -------------------------------------------------------------------------------- /test/07/indent.sh: -------------------------------------------------------------------------------- 1 | if a; then 2 | b 3 | if c; then 4 | d 5 | fi 6 | fi 7 | -------------------------------------------------------------------------------- /test/07/reference.sh: -------------------------------------------------------------------------------- 1 | if a; then 2 | b 3 | if c; then 4 | d 5 | fi 6 | fi 7 | -------------------------------------------------------------------------------- /test/08/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et ft=zsh nofoldenable' \ 8 | -c 'norm! oadd another comment' \ 9 | -c ':3' \ 10 | -c 'norm! oand another comment' \ 11 | -c ':saveas! output.sh' \ 12 | -c ':q!' indent.sh 13 | -------------------------------------------------------------------------------- /test/08/indent.sh: -------------------------------------------------------------------------------- 1 | # this comment has 'if' in it 2 | # this comment does not 3 | -------------------------------------------------------------------------------- /test/08/reference.sh: -------------------------------------------------------------------------------- 1 | # this comment has 'if' in it 2 | # add another comment 3 | # this comment does not 4 | # and another comment 5 | -------------------------------------------------------------------------------- /test/09/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/09/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | func() { 4 | if 1; then 5 | # a comment containing the if keyword 6 | echo 7 | else 8 | echo 9 | fi 10 | } 11 | -------------------------------------------------------------------------------- /test/09/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | func() { 4 | if 1; then 5 | # a comment containing the if keyword 6 | echo 7 | else 8 | echo 9 | fi 10 | } 11 | -------------------------------------------------------------------------------- /test/10/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/10/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function g { 4 | grep --color=always -nre "$1" ./* 5 | } 6 | -------------------------------------------------------------------------------- /test/10/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function g { 4 | grep --color=always -nre "$1" ./* 5 | } 6 | -------------------------------------------------------------------------------- /test/11/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/11/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test() { 4 | echo "something" 5 | 6 | { 7 | echo "more" 8 | echo "even more" 9 | } | tee /dev/null 10 | 11 | # TODO: this is most-likely wrong, it should be indented by 1 indent like line 4 12 | echo "last" 13 | } 14 | -------------------------------------------------------------------------------- /test/11/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | test() { 4 | echo "something" 5 | 6 | { 7 | echo "more" 8 | echo "even more" 9 | } | tee /dev/null 10 | 11 | # TODO: this is most-likely wrong, it should be indented by 1 indent like line 4 12 | echo "last" 13 | } 14 | -------------------------------------------------------------------------------- /test/12/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/12/indent.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ -z "somecondition" ]]; then 4 | if [[ -z "thircondition" ]]; then 5 | # below command will also break formatting as it has if keyword 6 | echo "if in double quoted string" 7 | echo 'if in single quoted string' 8 | fi 9 | fi 10 | -------------------------------------------------------------------------------- /test/12/reference.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ -z "somecondition" ]]; then 4 | if [[ -z "thircondition" ]]; then 5 | # below command will also break formatting as it has if keyword 6 | echo "if in double quoted string" 7 | echo 'if in single quoted string' 8 | fi 9 | fi 10 | -------------------------------------------------------------------------------- /test/13/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/13/indent.sh: -------------------------------------------------------------------------------- 1 | if a; then 2 | b if 3 | fi 4 | -------------------------------------------------------------------------------- /test/13/reference.sh: -------------------------------------------------------------------------------- 1 | if a; then 2 | b if 3 | fi 4 | -------------------------------------------------------------------------------- /test/14/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/14/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | a | 4 | b 5 | c 6 | -------------------------------------------------------------------------------- /test/14/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | a | 4 | b 5 | c 6 | -------------------------------------------------------------------------------- /test/15/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/15/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | f(){ 4 | for fn in a b c 5 | do 6 | for-script $fn 7 | done 8 | } 9 | -------------------------------------------------------------------------------- /test/15/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | f(){ 4 | for fn in a b c 5 | do 6 | for-script $fn 7 | done 8 | } 9 | -------------------------------------------------------------------------------- /test/16/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':let g:is_bash=1' \ 7 | -c ':so ../../indent/sh.vim' \ 8 | -c ':set sw=0 sts=-1 ts=2 et' \ 9 | -c 'norm! gg=G' \ 10 | -c ':saveas! output.sh' \ 11 | -c ':q!' indent.sh 12 | -------------------------------------------------------------------------------- /test/16/indent.sh: -------------------------------------------------------------------------------- 1 | ste(){ 2 | local attrs=( 3 | "asdf" 4 | "asdf2" 5 | "asdf3" 6 | ) 7 | } 8 | 9 | ste(){ 10 | attrs=( 11 | "asdf" 12 | # asdf 13 | "asdf2" 14 | # asdf 15 | "asdf3" 16 | ) 17 | } 18 | 19 | ste(){ 20 | local attrs 21 | attrs=( 22 | "asdf" 23 | "asdf2" 24 | "asdf3" 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /test/16/reference.sh: -------------------------------------------------------------------------------- 1 | ste(){ 2 | local attrs=( 3 | "asdf" 4 | "asdf2" 5 | "asdf3" 6 | ) 7 | } 8 | 9 | ste(){ 10 | attrs=( 11 | "asdf" 12 | # asdf 13 | "asdf2" 14 | # asdf 15 | "asdf3" 16 | ) 17 | } 18 | 19 | ste(){ 20 | local attrs 21 | attrs=( 22 | "asdf" 23 | "asdf2" 24 | "asdf3" 25 | ) 26 | } 27 | -------------------------------------------------------------------------------- /test/17/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/17/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DOTFILES=( 4 | ".bashrc" 5 | ".bash_profile" 6 | ".gitconfig" 7 | ".profile" 8 | ) 9 | 10 | if true; then 11 | echo 'pipe beginning' 12 | sed 's/beginn/end/' 13 | fi 14 | -------------------------------------------------------------------------------- /test/17/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | DOTFILES=( 4 | ".bashrc" 5 | ".bash_profile" 6 | ".gitconfig" 7 | ".profile" 8 | ) 9 | 10 | if true; then 11 | echo 'pipe beginning' 12 | sed 's/beginn/end/' 13 | fi 14 | -------------------------------------------------------------------------------- /test/18/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/18/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if true; then 4 | if false; then 5 | cmd with --if-option 6 | fi 7 | fi 8 | 9 | if true; then 10 | if false; then 11 | # fi 12 | fi 13 | fi 14 | 15 | if true; then 16 | if false; then 17 | cmd with --fi-option 18 | fi 19 | fi 20 | -------------------------------------------------------------------------------- /test/18/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | if true; then 4 | if false; then 5 | cmd with --if-option 6 | fi 7 | fi 8 | 9 | if true; then 10 | if false; then 11 | # fi 12 | fi 13 | fi 14 | 15 | if true; then 16 | if false; then 17 | cmd with --fi-option 18 | fi 19 | fi 20 | -------------------------------------------------------------------------------- /test/19/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/19/indent.sh: -------------------------------------------------------------------------------- 1 | stc(){ 2 | local attrs=( 3 | ["Bold"]="1" # Bold text only, keep colors 4 | # this 5 | ["Bold"]="1" # Bold text only, keep colors 6 | # Basic High Intensity Background High Intensity Background 7 | ["Black"]="30" ["IBlack"]="90" ["OnBlack"]="40" ["OnIBlack"]="100" 8 | ) 9 | } 10 | 11 | std(){ 12 | local attrs=( 13 | ["Bold"]="1" # Bold text only, keep colors 14 | 15 | # this 16 | ["Bold"]="1" # Bold text only, keep colors 17 | 18 | # Basic High Intensity Background High Intensity Background 19 | ["Black"]="30" ["IBlack"]="90" ["OnBlack"]="40" ["OnIBlack"]="100" 20 | ) 21 | } 22 | 23 | ste(){ 24 | local attrs 25 | attrs=( 26 | ["Bold"]="1" # Bold text only, keep colors 27 | 28 | # this 29 | ["Bold"]="1" # Bold text only, keep colors 30 | 31 | # Basic High Intensity Background High Intensity Background 32 | ["Black"]="30" ["IBlack"]="90" ["OnBlack"]="40" ["OnIBlack"]="100" 33 | ) 34 | } 35 | -------------------------------------------------------------------------------- /test/19/reference.sh: -------------------------------------------------------------------------------- 1 | stc(){ 2 | local attrs=( 3 | ["Bold"]="1" # Bold text only, keep colors 4 | # this 5 | ["Bold"]="1" # Bold text only, keep colors 6 | # Basic High Intensity Background High Intensity Background 7 | ["Black"]="30" ["IBlack"]="90" ["OnBlack"]="40" ["OnIBlack"]="100" 8 | ) 9 | } 10 | 11 | std(){ 12 | local attrs=( 13 | ["Bold"]="1" # Bold text only, keep colors 14 | 15 | # this 16 | ["Bold"]="1" # Bold text only, keep colors 17 | 18 | # Basic High Intensity Background High Intensity Background 19 | ["Black"]="30" ["IBlack"]="90" ["OnBlack"]="40" ["OnIBlack"]="100" 20 | ) 21 | } 22 | 23 | ste(){ 24 | local attrs 25 | attrs=( 26 | ["Bold"]="1" # Bold text only, keep colors 27 | 28 | # this 29 | ["Bold"]="1" # Bold text only, keep colors 30 | 31 | # Basic High Intensity Background High Intensity Background 32 | ["Black"]="30" ["IBlack"]="90" ["OnBlack"]="40" ["OnIBlack"]="100" 33 | ) 34 | } 35 | -------------------------------------------------------------------------------- /test/20/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # like test 19, but this time 4 | # do not handle it as 'bash' 5 | vim --clean \ 6 | -c ':unlet! b:did_indent' \ 7 | -c ':delfunc! GetShIndent' \ 8 | -c ':so ../../indent/sh.vim' \ 9 | -c ':let g:is_bash=1' \ 10 | -c ':set sw=0 sts=-1 ts=2 et' \ 11 | -c 'norm! gg=G' \ 12 | -c ':saveas! output.sh' \ 13 | -c ':q!' indent.sh 14 | -------------------------------------------------------------------------------- /test/20/indent.sh: -------------------------------------------------------------------------------- 1 | 2 | # make the actual i3 config file from pieces 3 | # 4 | mki3conf(){ 5 | ( 6 | cd ~/.config/i3 || return 7 | make && i3-msg reload 8 | ) 9 | } 10 | 11 | ( 12 | cd ~/.config/i3 || return 13 | make && i3-msg reload 14 | ) 15 | 16 | ( 17 | ( 18 | cd ~/.config/i3 || return 19 | make && i3-msg reload 20 | ) 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /test/20/reference.sh: -------------------------------------------------------------------------------- 1 | 2 | # make the actual i3 config file from pieces 3 | # 4 | mki3conf(){ 5 | ( 6 | cd ~/.config/i3 || return 7 | make && i3-msg reload 8 | ) 9 | } 10 | 11 | ( 12 | cd ~/.config/i3 || return 13 | make && i3-msg reload 14 | ) 15 | 16 | ( 17 | ( 18 | cd ~/.config/i3 || return 19 | make && i3-msg reload 20 | ) 21 | ) 22 | 23 | -------------------------------------------------------------------------------- /test/21/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/21/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # vim: set ft=bash sw=2 noet: 3 | 4 | a = 10 5 | b = 20 6 | 7 | function add() { 8 | c = $((a + b)) 9 | } 10 | 11 | function print { 12 | # do nothing 13 | } 14 | 15 | if [[ $c -ge 15 ]]; 16 | then 17 | print("ok") 18 | else 19 | print("not ok") 20 | fi 21 | -------------------------------------------------------------------------------- /test/21/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # vim: set ft=bash sw=2 noet: 3 | 4 | a = 10 5 | b = 20 6 | 7 | function add() { 8 | c = $((a + b)) 9 | } 10 | 11 | function print { 12 | # do nothing 13 | } 14 | 15 | if [[ $c -ge 15 ]]; 16 | then 17 | print("ok") 18 | else 19 | print("not ok") 20 | fi 21 | -------------------------------------------------------------------------------- /test/22/cmd.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | vim --clean \ 4 | -c ':unlet! b:did_indent' \ 5 | -c ':delfunc! GetShIndent' \ 6 | -c ':so ../../indent/sh.vim' \ 7 | -c ':set sw=0 sts=-1 ts=2 et' \ 8 | -c 'norm! gg=G' \ 9 | -c ':saveas! output.sh' \ 10 | -c ':q!' indent.sh 11 | -------------------------------------------------------------------------------- /test/22/indent.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # vim: set ft=bash sw=2 noet: 3 | 4 | function variables(){ 5 | local test1="test1" 6 | test2=( 7 | "test" "test2" 8 | ) 9 | local test3=( 10 | "test" "test3" 11 | ) 12 | typeset -ua test4=( 13 | "test" "test4" 14 | ) 15 | declare -a inline=("also work") multiline=( 16 | "multiple" "values" 17 | ) 18 | declare -l var="VALUE" 19 | } 20 | -------------------------------------------------------------------------------- /test/22/reference.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # vim: set ft=bash sw=2 noet: 3 | 4 | function variables(){ 5 | local test1="test1" 6 | test2=( 7 | "test" "test2" 8 | ) 9 | local test3=( 10 | "test" "test3" 11 | ) 12 | typeset -ua test4=( 13 | "test" "test4" 14 | ) 15 | declare -a inline=("also work") multiline=( 16 | "multiple" "values" 17 | ) 18 | declare -l var="VALUE" 19 | } 20 | -------------------------------------------------------------------------------- /test/indent1.sh: -------------------------------------------------------------------------------- 1 | echo this example below works 2 | [[ true ]] && { 3 | : 4 | } || { 5 | : 6 | } 7 | echo 'this line should not be indented' 8 | 9 | echo this example below NOT works 10 | [[ true ]] && 11 | { 12 | : 13 | } || { 14 | : 15 | } 16 | echo 'this line should not be indented' 17 | 18 | echo this example below NOT works 19 | [[ true ]] && 20 | { 21 | : 22 | } || { 23 | : 24 | } 25 | echo 'this line should not be indented' 26 | 27 | echo this example below NOT works 28 | [[ true ]] && 29 | { 30 | : 31 | } || 32 | { 33 | : 34 | } 35 | echo 'this line should not be indented' 36 | 37 | -------------------------------------------------------------------------------- /test/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | #set -x 4 | 5 | # Setup some color variables 6 | red=$(tput setaf 1) 7 | green=$(tput setaf 2) 8 | reset=$(tput sgr0) 9 | rc=0 10 | 11 | for i in */; do 12 | { 13 | cd "$i" && 14 | test -f "cmd.sh" && 15 | ./cmd.sh 16 | diff -qu output.sh reference.sh >/dev/null 17 | if [ $? -ne 0 ]; then 18 | printf "Test %s:\t\t[${red}Failed${reset}]\n" ${i%%/} 19 | if [ -n "$1" ] && [ "${1}" = "-v" ]; then 20 | diff -u --color reference.sh output.sh 21 | fi 22 | rc=1 23 | else 24 | printf "Test %s:\t\t[${green}OK${reset}]\n" ${i%%/} 25 | fi 26 | cd "$OLDPWD" 27 | } 28 | done 29 | exit $rc 30 | -------------------------------------------------------------------------------- /vim-sh-indent.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chrisbra/vim-sh-indent/982fbbc34f9c66af1f6b58b643d0f4ef32b7d8c8/vim-sh-indent.zip --------------------------------------------------------------------------------