|
| 1 | +# Using Different Dictionaries Based on Filename |
| 2 | +<!--- cspell:ignore esac getopts shopt ---> |
| 3 | + |
| 4 | +For example, using Bash dictionary with Markdown or text files, by filename (the |
| 5 | +default is to only apply from within VSCode for files of type `shellscript`). |
| 6 | + |
| 7 | +This is the same for use with `pre-commit` as with other methods of invoking |
| 8 | +`cspell`, namely configuring an `overrides` section on your `cspell.json` |
| 9 | +or equivalent file. |
| 10 | + |
| 11 | +The [current overrides documentation on the |
| 12 | +website](https://cspell.org/configuration/overrides/) covers a different type of |
| 13 | +scenario, so here is an example of selecting adding a dictionary to apply to |
| 14 | +specific folders. |
| 15 | + |
| 16 | +## Using Bash dictionary with Markdown or text files by filename |
| 17 | + |
| 18 | +Given a `cspell.json` as follows: |
| 19 | + |
| 20 | +``` json |
| 21 | +{ |
| 22 | + "overrides": [ |
| 23 | + { |
| 24 | + "filename": ["**/bash_examples/**", "**/bash_docs/**.md"], |
| 25 | + "dictionaries": [ |
| 26 | + "bash" |
| 27 | + ] |
| 28 | + } |
| 29 | + ], |
| 30 | + "version": "0.2" |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +Add the following code as `docs/bash_docs/a-silly-bash-code-block.md` |
| 35 | + |
| 36 | +```` markdown |
| 37 | +## Sample code block |
| 38 | + |
| 39 | +```sh |
| 40 | +if grep -r "something" .; then |
| 41 | + echo "Found" |
| 42 | +fi |
| 43 | + |
| 44 | +case "a string with 3" in |
| 45 | +with) |
| 46 | + echo "Why?" |
| 47 | + ;; |
| 48 | +esac |
| 49 | + |
| 50 | +. ./.bash_aliases |
| 51 | + |
| 52 | +# We should use getopts |
| 53 | + |
| 54 | +shopt -p |
| 55 | +``` |
| 56 | + |
| 57 | +## And another topic |
| 58 | + |
| 59 | +Words, many words. |
| 60 | +```` |
| 61 | + |
| 62 | +Add the following file as `examples/bash_examples/a-silly-bash-script` |
| 63 | + |
| 64 | +``` markdown |
| 65 | +#!/bin/bash |
| 66 | + |
| 67 | +if grep -r "something" .; then |
| 68 | + echo "Found" |
| 69 | +fi |
| 70 | + |
| 71 | +case "a string with 3" in |
| 72 | +with) |
| 73 | + echo "Why?" |
| 74 | + ;; |
| 75 | +esac |
| 76 | + |
| 77 | +. ./.bash_aliases |
| 78 | + |
| 79 | +# We should use getopts |
| 80 | + |
| 81 | +shopt -p |
| 82 | +``` |
| 83 | + |
| 84 | +And add the following code as `docs/about.md` |
| 85 | + |
| 86 | +```` markdown |
| 87 | +# Just a rather eccentric bash and markdown example for documentation purposes |
| 88 | + |
| 89 | +## Sample code block |
| 90 | + |
| 91 | +```sh |
| 92 | +if grep -r "something" .; then |
| 93 | + echo "Found" |
| 94 | +fi |
| 95 | + |
| 96 | +case "a string with 3" in |
| 97 | +with) |
| 98 | + echo "Why?" |
| 99 | + ;; |
| 100 | +esac |
| 101 | + |
| 102 | +. ./.bash_aliases |
| 103 | + |
| 104 | +# We should use getopts |
| 105 | + |
| 106 | +shopt -p |
| 107 | +``` |
| 108 | + |
| 109 | +## And another topic |
| 110 | + |
| 111 | +Words, many words. |
| 112 | +```` |
| 113 | + |
| 114 | +When `cspell` is invoked only `docs/about.md` should show errors. |
| 115 | + |
| 116 | +## Invoking CSpell |
| 117 | + |
| 118 | +### Via [`pre-commit`](https://pre-commit.com) |
| 119 | + |
| 120 | +#### Prerequisites |
| 121 | + |
| 122 | +* Project folder initialized as a git repository via `git init` or as part of a |
| 123 | +git repository cloned via `git clone` |
| 124 | +* ['pre-commit' installed](https://pre-commit.com/#install) |
| 125 | +* A `.pre-commit-config.yaml` such as: |
| 126 | + |
| 127 | + ```yaml |
| 128 | + fail_fast: true |
| 129 | + minimum_pre_commit_version: 2.18.1 |
| 130 | + |
| 131 | + repos: |
| 132 | + - repo: "https://github.com/streetsidesoftware/cspell-cli" |
| 133 | + rev: v6.5.0 |
| 134 | + hooks: |
| 135 | + - id: cspell |
| 136 | + ``` |
| 137 | +
|
| 138 | +#### Triggering CSpell using `pre-commit` |
| 139 | + |
| 140 | +* Stage all files |
| 141 | + |
| 142 | + ``` |
| 143 | + git add --all . |
| 144 | + ``` |
| 145 | +
|
| 146 | +* Execute: |
| 147 | +
|
| 148 | + ``` bash |
| 149 | + pre-commit run --all-files |
| 150 | + ``` |
| 151 | + |
| 152 | + OR commit the changes |
| 153 | + |
| 154 | + ``` bash |
| 155 | + git commit |
| 156 | + ``` |
| 157 | + |
| 158 | +### Via Command line |
| 159 | + |
| 160 | +* Execute |
| 161 | + |
| 162 | + ``` bash |
| 163 | + cspell '**' |
| 164 | + ``` |
| 165 | + |
0 commit comments