Debian Codegraph @

CHANGELOG.md

raw
1 # Changelog
2
3 ## [3.14.0] - 2026-08-28
4
5 This release drops support for Go 1.25 and includes many enhancements,
6 particularly in the interpreter, which implements more shell features
7 and fixes many divergences from Bash.
8
9 - **cmd/shfmt**
10 - Add `--detect` to find shell files by executable bit or shebang - #944
11 - **syntax**
12 - Add `Preorder`, an iterator over all nodes, complementing `Walk`
13 - Add `encoding.TextUnmarshaler` implementations for each operator type
14 - Support `${ foo;}` and `${|foo;}` inside double quotes - #1368
15 - Support array elements in `{varname}` redirects, like `exec {fds[3]}>&-` - #719
16 - Backslashes inside backquotes within double quotes escape double quotes - #1083
17 - Allow pound signs in associative array keys like `${args[cmd,#]}` - #1285
18 - Don't treat `#` as the start of a comment inside `[[ ]]` tests - #1326
19 - Don't join `then` or `do` with a semicolon when heredocs are pending - #1047
20 - Print a space after `!` in arithmetic expressions, avoiding history expansion - #987
21 - Space nested closing parentheses like the opening ones - #876
22 - Make `SplitBraces` reject malformed sequences and skip backslash escapes - #1330
23 - Zsh: support the `${=name}`, `${~name}`, and `${^name}` prefixes - #1238
24 - Zsh: support the `;|` case terminator and leading parentheses for globs - #1293, #1279
25 - Zsh: parse subscript flag arguments as patterns, and allow `[` globs in arrays - #1278, #1322
26 - **syntax/typedjson**
27 - Encode operators as their syntax form, such as `">>"`, rather than integers - #1321
28 - Return errors rather than panicking on malformed input
29 - **interp**
30 - Add `BashOpts` to set Bash options like `shopt` - #962
31 - Add `AccessHandler` to control file access checks, used by `-r` and `cd` - #1318
32 - Add `HandlerContext.LastExitStatus`, and provide a `HandlerContext` to stat handlers
33 - Implement the `help` and `times` builtins, as well as `$-` - #1398
34 - Implement the `;&` and `;;&` case terminators - #1391
35 - Implement the `-N` test operator, and make `-nt` and `-ot` follow POSIX - #1340
36 - Support sparse indexed arrays such as `a=([5]=x)` - #1373
37 - Run files as shell scripts when `exec` fails with `ENOEXEC` - #1065
38 - Support empty here-documents, and don't expand quoted ones - #1390
39 - Support `js/wasm`, where subprocesses and pipes are unavailable
40 - Keep the redirections applied by `exec` with no arguments
41 - Only fire the exit trap when the shell exits, rather than after every `Run`
42 - **expand**
43 - Add `BracesSeq` with a config and error reporting, deprecating `Braces`
44 - Add `Variable.Indexes` to describe sparse indexed arrays
45 - Support integer bases in arithmetic - #339
46 - Short-circuit the arithmetic `&&` and `||` operators - #1371
47 - Apply per-element operators to quoted array expansions like `"${a[@]%o}"` - #1081
48 - Make unquoted `${!arr[@]}` consistent with the quoted form - #672
49 - Fix many divergences from Bash in arithmetic, string, and brace expansions
50 - Reject unsupported Zsh syntax rather than panicking - #1363
51 - **pattern**
52 - Treat an unmatched `[` as a literal character, like Bash - #1372
53 - Fix panics and mismatches in bracket expressions, such as `[![:space:]]`
54 - **fileutil**
55 - Recognize `dash` shebangs as POSIX shell for `-ln=auto` - #1307
56
57 ## [3.13.1] - 2026-03-09
58
59 - **cmd/shfmt**
60 - Add support for `[[zsh]]` in EditorConfig files
61 - Detect the shell variant from filenames like `.zshrc` and `.bash_profile`
62 - Fix `--apply-ignore` when used with explicit args - #1310
63 - **syntax**
64 - Revert an accidental change to how array subscripts are formatted - #1314
65 - Never join `;;` with the previous line when formatting - #1289
66 - Fix a bug where `$1[foo]` was parsed as a subscript in Zsh - #1288
67 - Correctly parse `$!` in double quotes in Zsh - #1298
68 - Allow indexing into special parameters in Zsh - #1299
69 - Allow parameter expansions with empty names in Zsh - #1280
70 - **interp**
71 - Test against Bash 5.3 and fix three new discrepancies
72 - Fix a few bugs related to `nameref` variables
73 - Avoid panics when user input encounters unimplemented features
74
75 ## [3.13.0] - 2026-03-09
76
77 This release introduces support for [Zsh](https://www.zsh.org/)
78 in the parser and formatter, which was tracked in issue #120
79 alongside the label https://github.com/mvdan/sh/labels/zsh.
80 While support is not complete, it should be far enough for many use cases.
81
82 This release also drops support for Go 1.24 and includes many other enhancements:
83
84 - **cmd/shfmt**
85 - Exit with a non-zero status when `-l` prints any filenames
86 - `shfmt -version` is now derived from the git current tag, dropping the `-ldflags` workaround
87 - **syntax**
88 - New nodes types and node fields are introduced alongside `LangZsh`
89 - `LangVariant` is now a bitset, allowing the use of sets like "Bash-like"
90 - Add `InteractiveSeq` and `StmtsSeq` iterator methods for `Parser`
91 - Stop exposing the internal buffer in `Printer` via struct embedding
92 - Support the use of brace expansions like `declare {a,b}_c=value`
93 - Fix a bug where POSIX and Bash incorrectly allowed empty command lists
94 - **interp**
95 - Add support for `shopt -s dotglob` and `shopt -s extglob`
96 - Add support for simple uses of `!(expr)` extended glob patterns
97 - Support more builtin flags for `declare`, `type`, `read`
98 - Fix various bugs relating to nulls, errors, and arrays
99 - **expand**
100 - Add `Config.DotGlob` and `Config.ExtGlob` for the interpreter
101 - Add `Variable.Flags` to get the one-character `declare` flags
102 - Do not force env vars on Windows to be uppercase
103 - Fix various bugs relating to glob pattern matching
104 - **pattern**
105 - Add `GlobLeadingDot` and `ExtendedOperators` for the interpreter
106 - Add `NegExtGlobError` to mark the use of `!(expr)` negation patterns
107
108 ## [3.12.0] - 2025-07-06
109
110 - The `mvdan-sh` JS package is discontinued in favor of `sh-syntax` - #1145
111 - **cmd/shfmt**
112 - Support the "simplify" and "minify" flags via EditorConfig - #819
113 - Do not allow `--write` to replace non-regular files - #843
114 - **interp**
115 - Add `IsBuiltin` to check if a command name is a shell built-in - #1164
116 - Add `HandlerContext.Builtin` to allow `ExecHandlerFunc` to call built-ins
117 - Initial support for `$!` and `wait PID` - #221
118 - Return non-fatal `ExecHandlerFunc` errors via the `Runner.Run` API
119 - Add `HandlerContext.Pos` to provide handlers with source positions
120 - Deprecate `NewExitStatus` and `IsExitStatus` in favor of `ExitStatus`
121 - Fix `wait` to always return the status of the last given job
122 - Copy all env vars for background subshells to avoid data races
123 - Support reading random numbers via `$RANDOM` and `$SRANDOM`
124 - Set `$BASH_REMATCH` when matching regular expressions via `=~`
125 - Support modifying local vars from the parent calling function
126 - **expand**
127 - Adjust which backslash sequences are expanded in here-docs - #1138
128 - Tweak tilde expansions to match Bash semantics
129 - **pattern**
130 - Remove the flawed and broken `Braces` mode; use `syntax.SplitBraces` instead
131 - Tweak `**` to only act as "globstar" when alone as a path element - #1149
132 - Tweak `*` and `**` to not match leading dots in basenames
133 - Add a `NoGlobStar` mode to match the POSIX semantics
134 - **fileutil**
135 - Treat all non-regular files as definitely not shell scripts - #1089
136
137 ## [3.11.0] - 2025-03-05
138
139 This release drops support for Go 1.22 and includes many enhancements.
140
141 - **cmd/shfmt**
142 - Support `-l=0` and `-f=0` to split filenames with null bytes - #1096
143 - **syntax**
144 - New iterator API: `Parser.WordsSeq`
145 - Fix `Parser.Incomplete` and `IsIncomplete` to work well with `Parser.Words` - #937
146 - Initial support for parsing incomplete shell via `RecoverErrors`
147 - Expand `LangError` to include which language was used when parsing
148 - **interp**
149 - Refactor setting variables to fix array declaration edge cases - #1108
150 - Fix `test` read/write/exec operators to work correctly on directories - #1116
151 - Replace the `cancelreader` dependency with `os.File.SetReadDeadline`
152 - Avoid waiting for process substitutions, matching Bash
153 - Skip `OpenHandler` when opening named pipes for process substitutions - #1120
154 - Use `TMPDIR` if set via `Env` to create temporary files such as named pipes
155 - **expand**
156 - New iterator API: `FieldsSeq`
157 - Correctly handle repeated backslashes in double quotes - #1106
158 - Don't expand backslashes inside here-documents - #1070
159 - Replace the `Unset` kind with a new `Variable.Set` boolean field
160
161 ## [3.10.0] - 2024-10-20
162
163 - **cmd/shfmt**
164 - Report the correct language variant in parser error messages - #1102
165 - Move `--filename` out of the parser options category - #1079
166 - **syntax**
167 - Parse all CRLF line endings as LF, including inside heredocs - #1088
168 - Count skipped backslashes inside backticks in position column numbers - #1098
169 - Count skipped null bytes in position column numbers for consistency
170 - **interp**
171 - Fix a regression in `v3.9.0` which broke redirecting files to stdin - #1099
172 - Fix a regression in `v3.9.0` where `HandlerContext.Stdin` was never nil
173 - Add an `Interactive` option to be used by interactive shells - #1100
174 - Support closing stdin, stdout, and stderr via redirections like `<&-`
175
176 ## [3.9.0] - 2024-08-16
177
178 This release drops support for Go 1.21 and includes many fixes.
179
180 - **cmd/shfmt**
181 - Switch the diff implementation to remove one dependency
182 - **syntax**
183 - Protect against overflows in position offset integers
184 - **interp**
185 - Use `os.Pipe` for stdin to prevent draining by subprocesses - #1085
186 - Support cancelling reads in builtins when stdin is a file - #1066
187 - Support the `nocaseglob` bash option - #1073
188 - Support the Bash 5.2 `@k` parameter expansion operator
189 - Support the `test -O` and `test -G` operators on non-Windows - #1080
190 - Support the `read -s` builtin flag - #1063
191 - **expand**
192 - Add support for case insensitive globbing - #1073
193 - Don't panic when pattern words are nil - #1076
194
195 A special thanks to @theclapp for their contributors to this release!
196
197 ## [3.8.0] - 2024-02-11
198
199 This release drops support for Go 1.19 and 1.20 and includes many
200 features and bugfixes, such as improving EditorConfig support in `shfmt`.
201
202 - **cmd/shfmt**
203 - Support EditorConfig language sections such as `[[shell]]` - #664
204 - Add `--apply-ignore` for tools and editors - #1037
205 - **syntax**
206 - Allow formatting redirects before all command argumetnts - #942
207 - Support brace expansions with uppercase letters - #1042
208 - Unescape backquotes in single quotes within backquotes - #1041
209 - Better error when using `function` in POSIX mode - #993
210 - Better column numbers for escapes inside backquotes - #1028
211 - **interp**
212 - Support parentheses in classic test commands - #1036
213 - Determine access to a directory via `unix.Access` - #1033
214 - Support subshells with `FuncEnviron` as `Env` - #1043
215 - Add support for `fs.DirEntry` via `ReadDirHandler2`
216 - **expand**
217 - Add support for `fs.DirEntry` via `ReadDir2`
218 - Support zero-padding in brace expansions - #1042
219
220 ## [3.7.0] - 2023-06-18
221
222 - **syntax**
223 - Correctly parse `$foo#bar` as a single word - #1003
224 - Make `&>` redirect operators an error in POSIX mode - #991
225 - Avoid producing invalid shell when minifying some heredocs - #923
226 - Revert the simplification of `${foo:-}` into `${foo-}` - #970
227 - **interp**
228 - Add `ExecHandlers` to support layering multiple middlewares - #964
229 - Add initial support for the `select` clause - #969
230 - Support combining the `errexit` and `pipefail` options - #870
231 - Set `EUID` just like `UID` - #958
232 - Replace panics on unimplemented builtins with errors - #999
233 - Tweak build tags to support building for `js/wasm` - #983
234 - **syntax/typedjson**
235 - Avoid `reflect.Value.MethodByName` to reduce binary sizes - #961
236
237 ## [3.6.0] - 2022-12-11
238
239 This release drops support for Go 1.17 and includes many features and fixes.
240
241 - **cmd/shfmt**
242 - Implement `--from-json` as the reverse of `--to-json` - [#900]
243 - Improve the quality of the `--to-json` output - [#900]
244 - Provide detected language when erroring with `-ln=auto` - [#803]
245 - **syntax**
246 - Don't require peeking two bytes after `echo *` - [#835]
247 - Simplify `${name:-}` to the equivalent `${name-}` - [#849]
248 - Don't print trailing whitespaces on nested subshells - [#814]
249 - Don't print extra newlines in some case clauses - [#779]
250 - Don't indent comments preceding case clause items - [#917]
251 - Allow escaped newlines before unquoted words again - [#873]
252 - Parse a redirections edge case without spaces - [#879]
253 - Give a helpful error when `<<<` is used in POSIX mode - [#881]
254 - Forbid `${!foo*}` and `${!foo@}` in mksh mode - [#929]
255 - Batch allocations less aggressively in the parser
256 - **syntax/typedjson**
257 - Expose `--from-json` and `--to-json` as Go APIs - [#885]
258 - **expand**
259 - Improve support for expanding array keys and values - [#884]
260 - Don't panic on unsupported syntax nodes - [#841]
261 - Don't panic on division by zero - [#892]
262 - Properly expand unquoted parameters with spaces - [#886]
263 - Trim spaces when converting strings to integers - [#928]
264 - **interp**
265 - Add initial implementation for `mapfile` and `readarray` - [#863]
266 - Improve matching patterns against multiple lines - [#866]
267 - Support `%b` in the `printf` builtin - [#955]
268 - Display all Bash options in `shopt` - [#877]
269 - **pattern**
270 - Add `EntireString` to match the entire string using `^$` - [#866]
271
272 ## [3.5.1] - 2022-05-23
273
274 - **cmd/shfmt**
275 - Fix the Docker publishing script bug which broke 3.5.0 - [#860]
276 - **interp**
277 - Support multi-line strings when pattern matching in `[[` - [#861]
278 - Invalid glob words are no longer removed with `nullglob` - [#862]
279 - **pattern**
280 - `Regexp` now returns the typed error `SyntaxError` - [#862]
281
282 ## [3.5.0] - 2022-05-11
283
284 This release drops support for Go 1.16 and includes many new features.
285
286 - **cmd/shfmt**
287 - Switch to `-ln=auto` by default to detect the shell language
288 - Add support for long flags, like `--indent` for `-i`
289 - **syntax**
290 - Allow extglob wildcards as function names like `@() { ... }`
291 - Add support for heredocs surrounded by backquotes
292 - Add support for backquoted inline comments
293 - Add `NewPos` to create `Pos` values externally
294 - Support escaped newlines with CRLF line endings
295 - `Minify` no longer omits a leading shebang comment
296 - Avoid printing escaped newlines in non-quoted words
297 - Fix some printer edge cases where comments weren't properly spaced
298 - **fileutil**
299 - Add `Shebang` to extract the shell language from a `#!` line
300 - **expand**
301 - Reimplement globstar `**` globbing for correctness
302 - Replace `os.Stat` as the last direct use of the filesystem
303 - **interp**
304 - Add `CallHandler` to intercept all interpreted `CallExpr` nodes
305 - Add `ReadDirHandler` to intercept glob expansion filesystem reads
306 - Add `StatHandler` to intercept `os.Stat` and `os.Lstat` calls
307 - Always surface exit codes from command substitutions
308 - Add initial and incomplete support for `set -x`
309 - Add support for `cd -` as `cd "$OLDPWD"`
310 - Avoid panic on `set - args`
311
312 ## [3.4.3] - 2022-02-19
313
314 - **cmd/shfmt**
315 - New Docker `v3` tag to track the latest stable version
316 - Don't duplicate errors when walking directories
317 - **interp**
318 - Properly handle empty paths in the `test` builtin
319 - Allow unsetting global vars from inside a function again
320 - Use `%w` to wrap errors in `Dir`
321
322 ## [3.4.2] - 2021-12-24
323
324 - The tests no longer assume what locales are installed
325 - **interp**
326 - Keep `PATH` list separators OS-specific to fix a recent regression
327 - Avoid negative elapsed durations in the `time` builtin
328
329 ## [3.4.1] - 2021-11-23
330
331 - **syntax**
332 - Don't return an empty string on empty input to `Quote`
333 - **expand**
334 - Properly sort in `ListEnviron` to avoid common prefix issues
335 - **interp**
336 - `export` used in functions now affects the global scope
337 - Support looking for scripts in `$PATH` in `source`
338 - Properly slice arrays in parameter expansions
339
340 ## [3.4.0] - 2021-10-01
341
342 This release drops support for Go 1.15,
343 which allows the code to start benefitting from `io/fs`.
344
345 - **cmd/shfmt**
346 - Walks directories ~10% faster thanks to `filepath.WalkDir`
347 - **syntax**
348 - Add `Quote` to mirror `strconv.Quote` for shell syntax
349 - Skip null characters when parsing, just like Bash
350 - Rewrite fuzzers with Go 1.18's native fuzzing
351 - **fileutil**
352 - Add `CouldBeScript2` using `io/fs.DirEntry`
353 - **expand**
354 - Skip or stop at null characters, just like Bash
355 - **interp**
356 - Set `GID` just like `UID`
357 - Add support for `read -p`
358 - Add support for `pwd` flags
359 - Create random FIFOs for process substitutions more robustly
360 - Avoid leaking an open file when interpreting `$(<file)`
361
362 ## [3.3.1] - 2021-08-01
363
364 - **syntax**
365 - Don't convert `&` in a separate line into `;`
366 - Fix a `BinaryNextLine` edge case idempotency bug
367 - Never start printing a command with an escaped newline
368 - **interp**
369 - Support calling `Runner.Reset` before `Runner.Run`
370 - Obey `set -e` for failed redirections
371
372 ## [3.3.0] - 2021-05-17
373
374 - **cmd/shfmt**
375 - Document the `FORCE_COLOR` env var to always use colors in diffs
376 - **syntax**
377 - Add the printer `SingleLine` option to avoid printing newlines
378 - Positions now use more bits for line numbers than column numbers
379 - Test operators like `&&` and `||` no longer escape newlines
380 - Properly handle closing backquotes in a few edge cases
381 - Properly handle trailing escaped newlines in heredocs
382 - **interp**
383 - Redesigned variable scoping to fix a number of edge cases
384 - Refactor `set -o nounset` support to fix many edge cases
385 - Deprecate `LookPath` in favor of `LookPathDir`
386 - Array element words are now expanded correctly
387 - Add support for `trap` with error and exit signals
388 - Add support for `shopt -s nullglob`
389 - Add support for `type -p`
390
391 ## [3.2.4] - 2021-03-08
392
393 - **cmd/shfmt**
394 - Don't stop handling arguments when one results in a failure
395 - **expand**
396 - Don't panic when a backslash is followed by EOF
397
398 ## [3.2.2] - 2021-01-29
399
400 - **syntax**
401 - Avoid comment position panic in the printer
402
403 ## [3.2.1] - 2020-12-02
404
405 - **syntax**
406 - Fix an endless loop when parsing single quotes in parameter expansions
407 - Properly print assignments using escaped newlines
408 - Print inline heredoc comments in the right place
409 - **interp**
410 - Always expand `~` in Bash test expressions
411 - **expand**
412 - Don't panic on out of bounds array index expansions
413
414 ## [3.2.0] - 2020-10-29
415
416 - **cmd/shfmt**
417 - Add a man page via [scdoc](https://sr.ht/~sircmpwn/scdoc/); see [shfmt.1.scd](cmd/shfmt/shfmt.1.scd)
418 - Add `-filename` to give a name to standard input
419 - **syntax**
420 - Add initial support for [Bats](https://github.com/bats-core/bats-core)
421 - Protect line and column position numbers against overflows
422 - Rewrite arithmetic parsing to fix operator precedence
423 - Don't add parentheses to `function f {...}` declarations for ksh support
424 - `KeepPadding` now obeys extra indentation when using space indentation
425 - Properly tokenize `((` within test expressions
426 - Properly tokenize single quotes within parameter expansions
427 - Obey print options inside `<<-` heredocs
428 - Don't simplify indexed parameter expansions in arithmetic expressions
429 - Improve parsing errors for missing test expressions
430 - `LangVariant` now implements [flag.Value](https://pkg.go.dev/flag#Value)
431 - **interp**
432 - Avoid panic on C-style loops which omit expressions
433 - `$@` and `$*` always exist, so `"$@"` can expand to zero words
434
435 ## [3.1.2] - 2020-06-26
436
437 - **syntax**
438 - Fix brace indentation when using `FunctionNextLine`
439 - Support indirect parameter expansions with transformations
440 - Stop heredoc bodies only when the entire line matches
441 - **interp**
442 - Make the tests pass on 32-bit platforms
443
444 ## [3.1.1] - 2020-05-04
445
446 - **cmd/shfmt**
447 - Recognise `function_next_line` in EditorConfig files
448 - **syntax**
449 - Don't ignore escaped newlines at the end of heredoc bodies
450 - Improve support for parsing regexes in test expressions
451 - Count columns for `KeepPadding` in bytes, to better support unicode
452 - Never let `KeepPadding` add spaces right after indentation
453 - **interp**
454 - Hide unset variables when executing programs
455
456 ## [3.1.0] - 2020-04-07
457
458 - Redesigned Docker images, including buildx and an Alpine variant
459 - **cmd/shfmt**
460 - Replace source files atomically when possible
461 - Support `ignore = true` in an EditorConfig to skip directories
462 - Add `-fn` to place function opening braces on the next line
463 - Improve behavior of `-f` when given non-directories
464 - Docker images and `go get` installs now embed good version information
465 - **syntax**
466 - Add support for nested here-documents
467 - Allow parsing for loops with braces, present in mksh and Bash
468 - Expand `CaseClause` to describe its `in` token
469 - Allow empty lines in Bash arrays in the printer
470 - Support disabling `KeepPadding`
471 - Avoid mis-printing some programs involving `&`
472 - **interp**
473 - Add initial support for Bash process substitutions
474 - Add initial support for aliases
475 - Fix an edge case where the status code would not be reset
476 - The exit status code can now reflect being stopped by a signal
477 - `test -t` now uses the interpreter's stdin/stdout/stderr files
478 - **expand**
479 - Improve the interaction of `@` and `*` with quotes and `IFS`
480
481 ## [3.0.2] - 2020-02-22
482
483 - **syntax**
484 - Don't indent after escaped newlines in heredocs
485 - Don't parse `*[i]=x` as a valid assignment
486 - **interp**
487 - Prevent subshells from defining funcs in the parent shells
488 - **expand**
489 - Parameters to `Fields` no longer get braces expanded in-place
490
491 ## [3.0.1] - 2020-01-11
492
493 - **cmd/shfmt**
494 - Fix an edge case where walking directories could panic
495 - **syntax**
496 - Only do a trailing read in `Parser.Stmts` if we have open heredocs
497 - Ensure comments are never folded into heredocs
498 - Properly tokenize `)` after a `=~` test regexp
499 - Stop parsing a comment at an escaped newline
500 - **expand**
501 - `"$@"` now expands to zero fields when there are zero parameters
502
503 ## [3.0.0] - 2019-12-16
504
505 This is the first stable release as a proper module, now under
506 `mvdan.cc/sh/v3/...`. Go 1.12 or later is supported.
507
508 A large number of changes have been done since the last feature release a year
509 ago. All users are encouraged to update. Below are the major highlights.
510
511 - **cmd/shfmt**
512 - Support for [EditorConfig](https://editorconfig.org/) files
513 - Drop the dependency on `diff` for the `-d` flag, now using pure Go
514 - **syntax**
515 - Overhaul escaped newlines, now represented as `WordPart` positions
516 - Improve some operator type names, to consistently convey meaning
517 - Completely remove `StmtList`
518 - Redesign `IfClause`, making its "else" another `IfClause` node
519 - Redesign `DeclClause` to remove its broken `Opts` field
520 - Brace expression parsing is now done with a `BraceExp` word part
521 - Improve comment alignment in `Printer` via a post-process step
522 - Add support for the `~` bitwise negation operator
523 - Record the use of deprecated tokens in the syntax tree
524 - **interp**
525 - Improve the module API as "handlers", to reduce confusion with Go modules
526 - Split `LookPath` out of `ExecHandler` to allow custom behavior
527 - `Run` now returns `nil` instead of `ShellExitStatus(0)`
528 - `OpenDevImpls` is removed; see `ExampleOpenHandler` for an alternative
529 - **expand**
530 - Redesign `Variable` to reduce allocations
531 - Add support for more escape sequences
532 - Make `Config` a bit more powerful via `func` fields
533 - Rework brace expansion via the new `BraceExp` word part
534 - **pattern**
535 - New package for shell pattern matching, extracted from `syntax`
536 - Add support for multiple modes, including filenames and braces
537
538 Special thanks to Konstantin Kulikov for his contribution to this release.
539
540 ## [2.6.4] - 2019-03-10
541
542 - **syntax**
543 - Support array elements without values, like `declare -A x=([index]=)`
544 - Parse `for i; do ...` uniquely, as it's short for `for i in "$@"`
545 - Add missing error on unclosed nested backquotes
546 - **expand**
547 - Don't expand tildes twice, fixing `echo ~` on Windows
548 - **interp**
549 - Fix the use of `Params` as an option to `New`
550 - Support lowercase Windows volume names in `$PATH`
551
552 ## [2.6.3] - 2019-01-19
553
554 - **expand**
555 - Support globs with path prefixes and suffixes, like `./foo/*/`
556 - Don't error when skipping non-directories in glob walks
557
558 ## [2.6.2] - 2018-12-08
559
560 - **syntax**
561 - Avoid premature reads in `Parser.Interactive` when parsing Unicode bytes
562 - Fix parsing of certain Bash test expression involving newlines
563 - `Redirect.End` now takes the `Hdoc` field into account
564 - `ValidName` now returns `false` for an empty string
565 - **expand**
566 - Environment variables on Windows are case insensitive again
567 - **interp**
568 - Don't crash on `declare $unset=foo`
569 - Fix a regression where executed programs would receive a broken environment
570
571 Note that the published Docker image was changed to set `shfmt` as the
572 entrypoint, so previous uses with arguments like `docker run mvdan/shfmt:v2.6.1
573 shfmt --version` should now be `docker run mvdan/shfmt:v2.6.2 --version`.
574
575 ## [2.6.1] - 2018-11-17
576
577 - **syntax**
578 - Fix `Parser.Incomplete` with some incomplete literals
579 - Fix parsing of Bash regex tests in some edge cases
580 - **interp**
581 - Add support for `$(<file)` special command substitutions
582
583 ## [2.6.0] - 2018-11-10
584
585 This is the biggest v2 release to date. It's now possible to write an
586 interactive shell, and it's easier and safer to perform shell expansions.
587
588 This will be the last major v2 version, to allow converting the project to a Go
589 module in v3.
590
591 - Go 1.10 or later required to build
592 - **syntax**
593 - Add `Parser.Interactive` to implement an interactive shell
594 - Add `Parser.Document` to parse a single here-document body
595 - Add `Parser.Words` to incrementally parse separate words
596 - Add the `Word.Lit` helper method
597 - Support custom indentation in `<<-` heredoc bodies
598 - **interp**
599 - Stabilize API and add some examples
600 - Introduce a constructor, and redesign `Runner.Reset`
601 - Move the context from a field to function parameters
602 - Remove `Runner.Stmt` in favor of `Run` with `ShellExitStatus`
603 - **shell**
604 - Stabilize API and add some examples
605 - Add `Expand`, as a more powerful `os.Expand`
606 - Add `Fields`, similar to the old `Runner.Fields`
607 - `Source*` functions now take a context
608 - `Source*` functions no longer try to sandbox
609 - **expand**
610 - New package, split from `interp`
611 - Allows performing shell expansions in a controlled way
612 - Redesigned `Environ` and `Variable` moved from `interp`
613
614 ## [2.5.1] - 2018-08-03
615
616 - **syntax**
617 - Fix a regression where semicolons would disappear within switch cases
618
619 ## [2.5.0] - 2018-07-13
620
621 - **syntax**
622 - Add support for Bash's `{varname}<` redirects
623 - Add `SpaceRedirects` to format redirects like `> word`
624 - Parse `$\"` correctly within double quotes
625 - A few fixes where minification would break programs
626 - Printing of heredocs within `<()` no longer breaks them
627 - Printing of single statements no longer adds empty lines
628 - Error on invalid parameter names like `${1a}`
629 - **interp**
630 - `Runner.Dir` is now always an absolute path
631 - **shell**
632 - `Expand` now supports expanding a lone `~`
633 - `Expand` and `SourceNode` now have default timeouts
634 - **cmd/shfmt**
635 - Add `-sr` to print spaces after redirect operators
636 - Don't skip empty string values in `-tojson`
637 - Include comment positions in `-tojson`
638
639 ## [2.4.0] - 2018-05-16
640
641 - Publish as a JS package, [mvdan-sh](https://www.npmjs.com/package/mvdan-sh)
642 - **syntax**
643 - Add `DebugPrint` to pretty-print a syntax tree
644 - Fix comment parsing and printing in some edge cases
645 - Indent `<<-` heredoc bodies if indenting with tabs
646 - Add support for nested backquotes
647 - Relax parser to allow quotes in arithmetic expressions
648 - Don't rewrite `declare foo=` into `declare foo`
649 - **interp**
650 - Add support for `shopt -s globstar`
651 - Replace `Runner.Env` with an interface
652 - **shell**
653 - Add `Expand` as a fully featured version of `os.Expand`
654 - **cmd/shfmt**
655 - Set appropriate exit status when `-d` is used
656
657 ## [2.3.0] - 2018-03-07
658
659 - **syntax**
660 - Case clause patterns are no longer forced on a single line
661 - Add `ExpandBraces`, to perform Bash brace expansion on words
662 - Improve the handling of backslashes within backquotes
663 - Improve the parsing of Bash test regexes
664 - **interp**
665 - Support `$DIRSTACK`, `${param[@]#word}`, and `${param,word}`
666 - **cmd/shfmt**
667 - Add `-d`, to display diffs when formatting differs
668 - Promote `-exp.tojson` to `-tojson`
669 - Add `Pos` and `End` fields to nodes in `-tojson`
670 - Inline `StmtList` fields to simplify the `-tojson` output
671 - Support `-l` on standard input
672
673 ## [2.2.1] - 2018-01-25
674
675 - **syntax**
676 - Don't error on `${1:-default}`
677 - Allow single quotes in `${x['str key']}` as well as double quotes
678 - Add support for `${!foo[@]}`
679 - Don't simplify `foo[$x]` to `foo[x]`, to not break string indexes
680 - Fix `Stmt.End` when the end token is the background operator `&`
681 - Never apply the negation operator `!` to `&&` and `||` lists
682 - Apply the background operator `&` to entire `&&` and `||` lists
683 - Fix `StopAt` when the stop string is at the beginning of the source
684 - In `N>word`, check that `N` is a valid numeric literal
685 - Fix a couple of crashers found via fuzzing
686 - **cmd/shfmt**
687 - Don't error if non-bash files can't be written to
688
689 ## [2.2.0] - 2018-01-18
690
691 - Tests on Mac and Windows are now ran as part of CI
692 - **syntax**
693 - Add `StopAt` to stop lexing at a custom arbitrary token
694 - Add `TranslatePattern` and `QuotePattern` for pattern matching
695 - Minification support added to the printer - see `Minify`
696 - Add ParamExp.Names to represent `${!prefix*}`
697 - Add TimeClause.PosixFormat for its `-p` flag
698 - Fix parsing of assignment values containing `=`
699 - Fix parsing of parameter expansions followed by a backslash
700 - Fix quotes in parameter expansion operators like `${v:-'def'}`
701 - Fix parsing of negated declare attributes like `declare +x name`
702 - Fix parsing of `${#@}`
703 - Reject bad parameter expansion operators like `${v@WRONG}`
704 - Reject inline array variables like `a=(b c) prog`
705 - Reject indexing of special vars like `${1[3]}`
706 - Reject `${!name}` when in POSIX mode
707 - Reject multiple parameter expansion actions like `${#v:-def}`
708 - **interp**
709 - Add Bash brace expansion support, including `{a,b}` and `{x..y}`
710 - Pattern matching actions are more correct and precise
711 - Exported some Runner internals, including `Vars` and `Funcs`
712 - Use the interpreter's `$PATH` to find binaries
713 - Roll our own globbing to use our own pattern matching code
714 - Support the `getopts` sh builtin
715 - Support the `read` bash builtin
716 - Numerous changes to improve Windows support
717 - **shell**
718 - New experimental package with high-level utility functions
719 - Add `SourceFile` to get the variables declared in a script
720 - Add `SourceNode` as a lower-level version of the above
721 - **cmd/shfmt**
722 - Add `-mn`, which minifies programs via `syntax.Minify`
723
724 ## [2.1.0] - 2017-11-25
725
726 - **syntax**
727 - Add `Stmts`, to parse one statement at a time
728 - Walk no longer ignores comments
729 - Parameter expansion end fixes, such as `$foo.bar`
730 - Whitespace alignment can now be kept - see `KeepPadding`
731 - Introduce an internal newline token to simplify the parser
732 - Fix `Block.Pos` to actually return the start position
733 - Fix mishandling of inline comments in two edge cases
734 - **interp**
735 - Expose `Fields` to expand words into strings
736 - First configurable modules - cmds and files
737 - Add support for the new `TimeClause`
738 - Add support for namerefs and readonly vars
739 - Add support for associative arrays (maps)
740 - More sh builtins: `exec return`
741 - More bash builtins: `command pushd popd dirs`
742 - More `test` operators: `-b -c -t -o`
743 - Configurable kill handling - see `KillTimeout`
744 - **cmd/shfmt**
745 - Add `-f` to just list all the shell files found
746 - Add `-kp` to keep the column offsets in place
747 - **cmd/gosh**
748 - Now supports a basic interactive mode
749
750 ## [2.0.0] - 2017-08-30
751
752 - The package import paths were moved to `mvdan.cc/sh/...`
753 - **syntax**
754 - Parser and Printer structs introduced with functional options
755 - Node positions are now independent - `Position` merged into `Pos`
756 - All comments are now attached to nodes
757 - Support `mksh` - MirBSD's Korn Shell, used in Android
758 - Various changes to the AST:
759 - `EvalClause` removed; `eval` is no longer parsed as a keyword
760 - Add support for Bash's `time` and `select`
761 - Merge `UntilClause` into `WhileClause`
762 - Moved `Stmt.Assigns` to `CallExpr.Assigns`
763 - Remove `Elif` - chain `IfClause` nodes instead
764 - Support for indexed assignments like `a[i]=b`
765 - Allow expansions in arithmetic expressions again
766 - Unclosed heredocs now produce an error
767 - Binary ops are kept in the same line - see `BinaryNextLine`
768 - Switch cases are not indented by default - see `SwitchCaseIndent`
769 - **cmd/shfmt**
770 - Add `-s`, which simplifies programs via `syntax.Simplify`
771 - Add `-ln <lang>`, like `-ln mksh`
772 - Add `-bn` to put binary ops in the next line, like in v1
773 - Add `-ci` to indent switch cases, like in v1
774 - **interp**
775 - Some progress made, though still experimental
776 - Most of POSIX done - some builtins remain to be done
777
778 ## [1.3.1] - 2017-05-26
779
780 - **syntax**
781 - Fix parsing of `${foo[$bar]}`
782 - Fix printer regression where `> >(foo)` would be turned into `>>(foo)`
783 - Break comment alignment on any line without a comment, fixing formatting issues
784 - Error on keywords like `fi` and `done` used as commands
785
786 ## [1.3.0] - 2017-04-24
787
788 - **syntax**
789 - Fix backslashes in backquote command substitutions
790 - Disallow some test expressions like `[[ a == ! b ]]`
791 - Disallow some parameter expansions like `${$foo}`
792 - Disallow some arithmetic expressions like `((1=3))` and `(($(echo 1 + 2)))`
793 - Binary commands like `&&`, `||` and pipes are now left-associative
794 - **fileutil**
795 - `CouldBeScript` may now return true on non-regular files such as symlinks
796 - **interp**
797 - New experimental package to interpret a `syntax.File` in pure Go
798
799 ## [1.2.0] - 2017-02-22
800
801 - **syntax**
802 - Add support for escaped characters in bash regular expressions
803 - **fileutil**
804 - New package with some code moved from `cmd/shfmt`, now importable
805 - New funcs `HasShebang` and `CouldBeScript`
806 - Require shebangs to end with whitespace to reject `#!/bin/shfoo`
807
808 ## [1.1.0] - 2017-01-05
809
810 - **syntax**
811 - Parse `[[ a = b ]]` like `[[ a == b ]]`, deprecating `TsAssgn` in favour of `TsEqual`
812 - Add support for the `-k`, `-G`, `-O` and `-N` unary operators inside `[[ ]]`
813 - Add proper support for `!` in parameter expansions, like `${!foo}`
814 - Fix a couple of crashes found via fuzzing
815 - **cmd/shfmt**
816 - Rewrite `[[ a = b ]]` into the saner `[[ a == b ]]` (see above)
817
818 ## [1.0.0] - 2016-12-13
819
820 - **syntax**
821 - Stable release, API now frozen
822 - `Parse` now reads input in chunks of 1KiB
823 - **cmd/shfmt**
824 - Add `-version` flag
825
826 ## [0.6.0] - 2016-12-05
827
828 - **syntax**
829 - `Parse` now takes an `io.Reader` instead of `[]byte`
830 - Invalid UTF-8 is now reported as an error
831 - Remove backtracking for `$((` and `((`
832 - `Walk` now takes a func literal to simplify its use
833
834 ## [0.5.0] - 2016-11-24
835
836 - **cmd/shfmt**
837 - Remove `-cpuprofile`
838 - Don't read entire files into memory to check for a shebang
839 - **syntax**
840 - Use `uint32` for tokens and positions in nodes
841 - Use `Word` and `Lit` pointers consistently instead of values
842 - Ensure `Word.Parts` is never empty
843 - Add support for expressions in array indexing and parameter expansion slicing
844
845 ## [0.4.0] - 2016-11-08
846
847 - Merge `parser`, `ast`, `token` and `printer` into a single package `syntax`
848 - Use separate operator types in nodes rather than `Token`
849 - Use operator value names that express their function
850 - Keep `;` if on a separate line when formatting
851 - **cmd/shfmt**
852 - Allow whitespace after `#!` in a shebang
853 - **syntax**
854 - Implement operator precedence for `[[ ]]`
855 - Parse `$(foo)` and ``foo`` as the same (`shfmt` then converts the latter to the former)
856 - Rename `Quoted` to `DblQuoted` for clarity
857 - Split `((foo))` nodes as their own type, `ArithmCmd`
858 - Add support for bash parameter expansion slicing
859
860 ## [0.3.0] - 2016-10-26
861
862 - Add support for bash's `coproc` and extended globbing like `@(foo)`
863 - Improve test coverage, adding tests to `cmd/shfmt` and bringing `parser` and `printer` close to 100%
864 - Support empty C-style for loops like `for ((;;)) ...`
865 - Support for the `>|` redirect operand
866 - **cmd/shfmt**
867 - Fix issue where `.sh` and `.bash` files might not be walked if running on a directory
868 - Fix issue where `-p` was not obeyed when formatting stdin
869 - **parser**
870 - `$''` now generates an `ast.SglQuoted`, not an `ast.Quoted`
871 - Support for ambiguous `((` like with `$((`
872 - Improve special parameter expansions like `$@` or `$!`
873 - Improve bash's `export` `typeset`, `nameref` and `readonly`
874 - `<>`, `>&` and `<&` are valid POSIX
875 - Support for bash's `^`, `^^`, `,` and `,,` operands inside `${}`
876
877 ## [0.2.0] - 2016-10-13
878
879 - Optimizations all around, making `shfmt` ~15% faster
880 - **cmd/shfmt**
881 - Add `-p` flag to only accept POSIX Shell programs (`parser.PosixConformant`)
882 - **parser**
883 - Add support for ambiguous `$((` as in `$((foo) | bar)`
884 - Limit more bash features to `PosixConformant` being false
885 - Don't parse heredoc bodies in nested expansions and contexts
886 - Run tests through `bash` to confirm the presence of a parse error
887 - **ast**
888 - Add `Walk(Visitor, Node)` function
889
890 ## [0.1.0] - 2016-09-20
891
892 Initial release.
893
894 [3.14.0]: https://github.com/mvdan/sh/releases/tag/v3.14.0
895 [3.13.1]: https://github.com/mvdan/sh/releases/tag/v3.13.1
896 [3.13.0]: https://github.com/mvdan/sh/releases/tag/v3.13.0
897 [3.12.0]: https://github.com/mvdan/sh/releases/tag/v3.12.0
898 [3.11.0]: https://github.com/mvdan/sh/releases/tag/v3.11.0
899 [3.10.0]: https://github.com/mvdan/sh/releases/tag/v3.10.0
900 [3.9.0]: https://github.com/mvdan/sh/releases/tag/v3.9.0
901 [3.8.0]: https://github.com/mvdan/sh/releases/tag/v3.8.0
902 [3.7.0]: https://github.com/mvdan/sh/releases/tag/v3.7.0
903
904 [3.6.0]: https://github.com/mvdan/sh/releases/tag/v3.6.0
905 [#779]: https://github.com/mvdan/sh/issues/779
906 [#803]: https://github.com/mvdan/sh/issues/803
907 [#814]: https://github.com/mvdan/sh/issues/814
908 [#835]: https://github.com/mvdan/sh/issues/835
909 [#841]: https://github.com/mvdan/sh/issues/841
910 [#849]: https://github.com/mvdan/sh/pull/849
911 [#863]: https://github.com/mvdan/sh/pull/863
912 [#866]: https://github.com/mvdan/sh/pull/866
913 [#873]: https://github.com/mvdan/sh/issues/873
914 [#877]: https://github.com/mvdan/sh/issues/877
915 [#879]: https://github.com/mvdan/sh/pull/879
916 [#881]: https://github.com/mvdan/sh/issues/881
917 [#884]: https://github.com/mvdan/sh/issues/884
918 [#885]: https://github.com/mvdan/sh/issues/885
919 [#886]: https://github.com/mvdan/sh/issues/886
920 [#892]: https://github.com/mvdan/sh/issues/892
921 [#900]: https://github.com/mvdan/sh/pull/900
922 [#917]: https://github.com/mvdan/sh/pull/917
923 [#928]: https://github.com/mvdan/sh/issues/928
924 [#929]: https://github.com/mvdan/sh/pull/929
925 [#955]: https://github.com/mvdan/sh/pull/955
926
927 [3.5.1]: https://github.com/mvdan/sh/releases/tag/v3.5.1
928 [#860]: https://github.com/mvdan/sh/issues/860
929 [#861]: https://github.com/mvdan/sh/pull/861
930 [#862]: https://github.com/mvdan/sh/pull/862
931
932 [3.5.0]: https://github.com/mvdan/sh/releases/tag/v3.5.0
933 [3.4.3]: https://github.com/mvdan/sh/releases/tag/v3.4.3
934 [3.4.2]: https://github.com/mvdan/sh/releases/tag/v3.4.2
935 [3.4.1]: https://github.com/mvdan/sh/releases/tag/v3.4.1
936 [3.4.0]: https://github.com/mvdan/sh/releases/tag/v3.4.0
937 [3.3.1]: https://github.com/mvdan/sh/releases/tag/v3.3.1
938 [3.3.0]: https://github.com/mvdan/sh/releases/tag/v3.3.0
939 [3.2.4]: https://github.com/mvdan/sh/releases/tag/v3.2.4
940 [3.2.2]: https://github.com/mvdan/sh/releases/tag/v3.2.2
941 [3.2.1]: https://github.com/mvdan/sh/releases/tag/v3.2.1
942 [3.2.0]: https://github.com/mvdan/sh/releases/tag/v3.2.0
943 [3.1.2]: https://github.com/mvdan/sh/releases/tag/v3.1.2
944 [3.1.1]: https://github.com/mvdan/sh/releases/tag/v3.1.1
945 [3.1.0]: https://github.com/mvdan/sh/releases/tag/v3.1.0
946 [3.0.2]: https://github.com/mvdan/sh/releases/tag/v3.0.2
947 [3.0.1]: https://github.com/mvdan/sh/releases/tag/v3.0.1
948 [3.0.0]: https://github.com/mvdan/sh/releases/tag/v3.0.0
949 [2.6.4]: https://github.com/mvdan/sh/releases/tag/v2.6.4
950 [2.6.3]: https://github.com/mvdan/sh/releases/tag/v2.6.3
951 [2.6.2]: https://github.com/mvdan/sh/releases/tag/v2.6.2
952 [2.6.1]: https://github.com/mvdan/sh/releases/tag/v2.6.1
953 [2.6.0]: https://github.com/mvdan/sh/releases/tag/v2.6.0
954 [2.5.1]: https://github.com/mvdan/sh/releases/tag/v2.5.1
955 [2.5.0]: https://github.com/mvdan/sh/releases/tag/v2.5.0
956 [2.4.0]: https://github.com/mvdan/sh/releases/tag/v2.4.0
957 [2.3.0]: https://github.com/mvdan/sh/releases/tag/v2.3.0
958 [2.2.1]: https://github.com/mvdan/sh/releases/tag/v2.2.1
959 [2.2.0]: https://github.com/mvdan/sh/releases/tag/v2.2.0
960 [2.1.0]: https://github.com/mvdan/sh/releases/tag/v2.1.0
961 [2.0.0]: https://github.com/mvdan/sh/releases/tag/v2.0.0
962 [1.3.1]: https://github.com/mvdan/sh/releases/tag/v1.3.1
963 [1.3.0]: https://github.com/mvdan/sh/releases/tag/v1.3.0
964 [1.2.0]: https://github.com/mvdan/sh/releases/tag/v1.2.0
965 [1.1.0]: https://github.com/mvdan/sh/releases/tag/v1.1.0
966 [1.0.0]: https://github.com/mvdan/sh/releases/tag/v1.0.0
967 [0.6.0]: https://github.com/mvdan/sh/releases/tag/v0.6.0
968 [0.5.0]: https://github.com/mvdan/sh/releases/tag/v0.5.0
969 [0.4.0]: https://github.com/mvdan/sh/releases/tag/v0.4.0
970 [0.3.0]: https://github.com/mvdan/sh/releases/tag/v0.3.0
971 [0.2.0]: https://github.com/mvdan/sh/releases/tag/v0.2.0
972 [0.1.0]: https://github.com/mvdan/sh/releases/tag/v0.1.0