Skip to content

Commit

Permalink
STYLE.md: add global flag to sed and add example to auto append nl to…
Browse files Browse the repository at this point in the history
… files

Signed-off-by: Christopher Degawa <ccom@randomderp.com>
  • Loading branch information
1480c1 committed Feb 3, 2020
1 parent 101085b commit ee708ce
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ After coding, make sure to trim any trailing white space and convert any tabs to
### For bash

``` bash
find . -name <Filename> -type f -exec sed -i 's/\t/ /;s/[[:space:]]*$//' {} +
find . -type f -name <Filename> ! -wholename "./.git/*" ! -name "*.png" ! -wholename "./Bin/*" ! -wholename "./Build/*" -exec sed -i 's/\t/ /g;s/[[:space:]]*$//g' {} +
```

Where `<Filename>` is `"*.c"` or `"*.(your file extention here)"`\
Expand All @@ -127,11 +127,18 @@ Search the `find` man page or tips and tricks for more options.\
Alternatively, for single file(s):

``` bash
sed -i 's/\t/ /;s/[[:space:]]*$//' <Filename/Filepath>
sed -i 's/\t/ /g;s/[[:space:]]*$//g' <Filename/Filepath>
```

Note: For macOS and BSD related distros, you may need to use `sed -i ''` inplace due to differences with GNU sed.

``` bash
git grep --cached -Ilz '' | while IFS= read -rd '' f; do tail -c1 < "$f" | read -r _ || echo >> "$f"; done
```

Use this to auto append a newline to the end of the file for any files that are under git.
Taken from [here](https://unix.stackexchange.com/a/161853)

### For Powershell/pwsh

``` Powershell
Expand Down

0 comments on commit ee708ce

Please sign in to comment.