bash-explainer 0.6.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -46,15 +46,66 @@ bash-explainer --check install.sh # constructs its shell (#!/bin/sh: dash…
46
46
  | `--shell <name>` | the script's shell: `bash`, `sh`, `dash`, `ash`, `yash`, `ksh`, `mksh`, `zsh` (default: from the shebang or the file name) |
47
47
  | `--kind <kind>` | what the file is: `shell`, `dockerfile`, `makefile`, `yaml`, `npm`, `markdown`, `python`, `jenkinsfile` (default: from the file name) |
48
48
  | `--lang <en\|ja>` | language (default: from `LANG`) |
49
+ | `--sarif <file>` | with `--check`, also write the problems to this file as SARIF, whatever `--format` prints (so one run gives annotations and a SARIF file) |
49
50
  | `--format <format>` | `text`, `markdown` or `json`; with `--check`, also `github` (annotations in GitHub Actions) or `sarif` (for code scanning) |
50
51
  | `--no-examples` | leave out worked examples |
52
+ | `--config <file>` | read the settings from this file (see [Settings](#settings)) |
53
+ | `--no-config` | read no settings file |
54
+ | `--set <key>=<value>` | set one setting, as named in VS Code (`--set shell=dash`, `--set notes.idioms=false`); may be repeated |
55
+ | `--print-config` | print the settings in effect, as JSON |
51
56
  | `--lsp` | run as a Language Server on standard input and output (see [In your editor](#in-your-editor-language-server)) |
52
57
  | `--color`, `--no-color` | colour the text output (default: when writing to a terminal; `NO_COLOR` turns it off) |
53
58
 
54
59
  In the text output, a construct is labelled with its keywords and a placeholder for what is left out (`while` *condition* `do` *commands* `done`): the placeholder is in italics and dim with colour, and shown as `‹condition›` without. With `--format json`, `label` is that text and `labelParts` lists the parts (`{ "text": "while" }`, `{ "text": "condition", "placeholder": true }`…).
55
60
 
61
+ A row or a note about a part of bash ends with the sections of the GNU Bash Reference Manual it is about: `(Bash manual 3.7.2)` in the text output, links to the sections on gnu.org with `--format markdown`. The numbers are those of the bash 5.2 manual. With `--format json`, a token has them in `refs` (`["3.7.2"]`), and `facts` lists the notes that come from the message catalog, with their `id`, `kind` (`note` or `pitfall`), `text` and `refs`.
62
+
56
63
  `--check` prints problems as compilers do (`file:line:column: warning: … [code]`), so editors and CI can pick them up. With `--format github` they become GitHub Actions annotations, shown on the pull request's diff; with `--format sarif`, a SARIF file for code scanning.
57
64
 
65
+ ## Settings
66
+
67
+ The tool takes the settings of the VS Code extension that have a meaning in a terminal: `language`, `notes.idioms`, `notes.pitfalls`, `shell`, `yq.flavor`, `diagnostics.ignore`, `diagnostics.embedded`, `examples.enabled`, `examples.disabled` and `customCommands` (see [Settings](https://github.com/sf624/bash-explainer#settings) for what each one does). They come from a JSON file with the keys of VS Code's `settings.json`, with or without `bashExplainer.`; comments and trailing commas are allowed, and nested objects too (`{ "notes": { "idioms": false } }`):
68
+
69
+ ```jsonc
70
+ {
71
+ // The shell to check scripts for, whatever their shebang says.
72
+ "bashExplainer.shell": "sh",
73
+ "bashExplainer.language": "ja",
74
+ "bashExplainer.diagnostics.ignore": ["crlf"],
75
+ "bashExplainer.examples.disabled": ["date"],
76
+ "bashExplainer.customCommands": {
77
+ "deploy": {
78
+ "summary": "Deploy a service to production",
79
+ "options": [{ "names": ["-n", "--dry-run"], "description": "only show what would happen" }]
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ The file is the one given with `--config`, else the one in `$BASH_EXPLAINER_CONFIG`, else `$XDG_CONFIG_HOME/bash-explainer/settings.json` (`~/.config/bash-explainer/settings.json` when `XDG_CONFIG_HOME` is not set). The last one may be missing; a file named with `--config` or `$BASH_EXPLAINER_CONFIG` must be there, and a file that is not JSON is an error (exit status 2). `--no-config` reads none. An unknown key, or a value of the wrong type, is left out with a warning on standard error. Settings that have a meaning only in VS Code or the Language Server (`hover.enabled`, `panel.autoOpen`…) are accepted and left alone, so the file can be a copy of the editor's settings.
86
+
87
+ `--set key=value` sets one setting; the value is read as JSON when it is JSON (`false`, `["crlf"]`), else as a string (`dash`). Each source overrides the ones before it:
88
+
89
+ 1. the defaults,
90
+ 2. the settings file,
91
+ 3. `--set`,
92
+ 4. `--lang`, `--shell` and `--no-examples`.
93
+
94
+ `--print-config` prints the settings in effect, as JSON that can be saved as a settings file:
95
+
96
+ ```console
97
+ $ bash-explainer --set shell=dash --print-config
98
+ {
99
+ "bashExplainer.language": "auto",
100
+ "bashExplainer.notes.idioms": true,
101
+ "bashExplainer.notes.pitfalls": true,
102
+ "bashExplainer.shell": "dash",
103
+ …
104
+ }
105
+ ```
106
+
107
+ With `language` set to `auto` (the default), the language follows `LC_ALL`, `LC_MESSAGES` or `LANG`.
108
+
58
109
  ## In CI (GitHub Actions)
59
110
 
60
111
  The repository is also a GitHub Action, which runs this tool at its own version:
@@ -74,7 +125,7 @@ Warnings appear on the pull request's diff, and fail the step (`fail-on-warning:
74
125
 
75
126
  ## In your editor (Language Server)
76
127
 
77
- `bash-explainer --lsp` is a Language Server on standard input and output: hover a line for its explanation, and get the warnings with their quick fixes, in any editor that speaks LSP. It handles shell scripts (language IDs `sh`, `bash`, `zsh`, `shellscript`…) and the shell code in Dockerfiles, Makefiles, YAML, `package.json`, Markdown, Python and Jenkinsfiles. It runs next to other servers, such as bash-language-server.
128
+ `bash-explainer --lsp` is a Language Server on standard input and output: hover a line for its explanation, and get the warnings with their quick fixes, in any editor that speaks LSP. With `highlight.enabled` on, it also colours the shell code (semantic tokens, from the same syntax tree as the explanations). It handles shell scripts (language IDs `sh`, `bash`, `zsh`, `shellscript`…) and the shell code in Dockerfiles, Makefiles, YAML, `package.json`, Markdown, Python and Jenkinsfiles. It runs next to other servers, such as bash-language-server.
78
129
 
79
130
  Install it with `npm install --global bash-explainer` (see [Installation](#installation)), so the editor does not wait for `npx`.
80
131
 
@@ -109,7 +160,7 @@ language-servers = ["bash-language-server", "bash-explainer"]
109
160
  (add-to-list 'eglot-server-programs '((sh-mode bash-ts-mode) . ("bash-explainer" "--lsp"))))
110
161
  ```
111
162
 
112
- Settings, as `initializationOptions` or through `workspace/didChangeConfiguration` (under `bashExplainer`): `language` (`en` or `ja`; default from `LANG`), `shell` (the shell to check for; default: from the file), `examples` (`false` leaves out worked examples).
163
+ Settings: the keys of the VS Code extension's settings that have a meaning here, as `initializationOptions` or through `workspace/didChangeConfiguration`, under `bashExplainer` or not, flat (`"diagnostics.ignore": ["crlf"]`) or nested (`diagnostics = { ignore = { 'crlf' } }`): `language`, `notes.idioms`, `notes.pitfalls`, `shell`, `yq.flavor`, `diagnostics.enabled`, `diagnostics.ignore`, `diagnostics.embedded`, `examples.enabled`, `examples.disabled`, `examples.inHover`, `hover.enabled`, `hover.maxDepth`, `highlight.enabled`, `languages` (more language IDs to read as shell scripts), `embedded.files` and `customCommands`. `examples: false`, as earlier releases read it, still turns the examples off. Under what the editor sends, the server reads the [settings file](#settings) of the command-line tool (also `--lsp --config <file>`). Keys and values it cannot use are reported in the editor's log (`window/logMessage`).
113
164
 
114
165
  ## Privacy
115
166
 
@@ -8,12 +8,13 @@ Bash Explainer includes the following third-party software (ISC, MIT). Their lic
8
8
 
9
9
  | Component | Version | License | Included as |
10
10
  | --- | --- | --- | --- |
11
- | [unbash](https://github.com/webpro-nl/unbash) | 6.0.0 | ISC | bundled into `dist/extension.js`; bundled into `dist/web/extension.js` |
11
+ | [unbash](https://github.com/webpro-nl/unbash) | 6.0.1 | ISC | bundled into `dist/extension.js`; bundled into `dist/web/extension.js` |
12
12
 
13
13
  ## In the web version
14
14
 
15
15
  | Component | Version | License | Included as |
16
16
  | --- | --- | --- | --- |
17
+ | [unbash](https://github.com/webpro-nl/unbash) | 6.0.1 | ISC | bundled into `app.js` |
17
18
  | [@codemirror/commands](https://code.haverbeke.berlin/codemirror/commands) | 6.11.1 | MIT | bundled into `app.js` |
18
19
  | [@codemirror/language](https://code.haverbeke.berlin/codemirror/language) | 6.13.1 | MIT | bundled into `app.js` |
19
20
  | [@codemirror/legacy-modes](https://code.haverbeke.berlin/codemirror/legacy-modes) | 6.5.5 | MIT | bundled into `app.js` |
@@ -26,17 +27,36 @@ Bash Explainer includes the following third-party software (ISC, MIT). Their lic
26
27
  | [@marijn/find-cluster-break](https://code.haverbeke.berlin/marijn/find-cluster-break) | 1.0.4 | MIT | bundled into `app.js` |
27
28
  | [crelt](https://code.haverbeke.berlin/marijn/crelt) | 1.0.7 | MIT | bundled into `app.js` |
28
29
  | [style-mod](https://code.haverbeke.berlin/marijn/style-mod) | 4.1.4 | MIT | bundled into `app.js` |
29
- | [unbash](https://github.com/webpro-nl/unbash) | 6.0.0 | ISC | bundled into `app.js` |
30
30
  | [w3c-keyname](https://github.com/marijnh/w3c-keyname#readme) | 2.2.8 | MIT | bundled into `app.js` |
31
31
 
32
32
  ## In the command-line tool (npm package bash-explainer)
33
33
 
34
34
  | Component | Version | License | Included as |
35
35
  | --- | --- | --- | --- |
36
- | [unbash](https://github.com/webpro-nl/unbash) | 6.0.0 | ISC | bundled into `dist/cli.js` |
36
+ | [unbash](https://github.com/webpro-nl/unbash) | 6.0.1 | ISC | bundled into `dist/cli.js` |
37
37
 
38
38
  ## License texts
39
39
 
40
+ ### unbash
41
+
42
+ ```text
43
+ ISC License
44
+
45
+ Copyright (c) Lars Kappert
46
+
47
+ Permission to use, copy, modify, and/or distribute this software for any
48
+ purpose with or without fee is hereby granted, provided that the above
49
+ copyright notice and this permission notice appear in all copies.
50
+
51
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
52
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
53
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
54
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
55
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
56
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
57
+ PERFORMANCE OF THIS SOFTWARE.
58
+ ```
59
+
40
60
  ### @codemirror/commands, @codemirror/language, @codemirror/legacy-modes, @codemirror/lint, @codemirror/state, @codemirror/streamparser, @codemirror/view
41
61
 
42
62
  ```text
@@ -163,26 +183,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
163
183
  THE SOFTWARE.
164
184
  ```
165
185
 
166
- ### unbash
167
-
168
- ```text
169
- ISC License
170
-
171
- Copyright (c) Lars Kappert
172
-
173
- Permission to use, copy, modify, and/or distribute this software for any
174
- purpose with or without fee is hereby granted, provided that the above
175
- copyright notice and this permission notice appear in all copies.
176
-
177
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
178
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
179
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
180
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
181
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
182
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
183
- PERFORMANCE OF THIS SOFTWARE.
184
- ```
185
-
186
186
  ### w3c-keyname
187
187
 
188
188
  ```text