Add ClangFormat to prettybat

This commit is contained in:
Ethan P 2019-09-26 18:02:21 -07:00
parent 24313f8281
commit 0621d14951
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA
2 changed files with 34 additions and 12 deletions

View File

@ -20,17 +20,20 @@ See `man bat` for more information.
## Languages
| Language | Formatter |
| -------------------- | ----------------------------------------------- |
| JavaScript (JS, JSX) | [prettier](https://prettier.io/) |
| TypeScript (TS, TSX) | [prettier](https://prettier.io/) |
| CSS, SCSS, SASS | [prettier](https://prettier.io/) |
| Markdown | [prettier](https://prettier.io/) |
| JSON | [prettier](https://prettier.io/) |
| YAML | [prettier](https://prettier.io/) |
| HTML | [prettier](https://prettier.io/) |
| Rust | [rustfmt](https://github.com/rust-lang/rustfmt) |
| Bash | [shfmt](https://github.com/mvdan/sh) |
| Language | Formatter |
| -------------------- | ----------------------------------------------------------- |
| JavaScript (JS, JSX) | [prettier](https://prettier.io/) |
| TypeScript (TS, TSX) | [prettier](https://prettier.io/) |
| CSS, SCSS, SASS | [prettier](https://prettier.io/) |
| Markdown | [prettier](https://prettier.io/) |
| JSON | [prettier](https://prettier.io/) |
| YAML | [prettier](https://prettier.io/) |
| HTML | [prettier](https://prettier.io/) |
| Rust | [rustfmt](https://github.com/rust-lang/rustfmt) |
| Bash | [shfmt](https://github.com/mvdan/sh) |
| C | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
| C++ | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |
| Objective-C | [ClangFormat](https://clang.llvm.org/docs/ClangFormat.html) |

View File

@ -14,7 +14,7 @@ source "${LIB}/print.sh"
# Formatters:
# -----------------------------------------------------------------------------
FORMATTERS=("prettier" "rustfmt" "shfmt")
FORMATTERS=("prettier" "rustfmt" "shfmt" "clangformat")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -40,6 +40,24 @@ formatter_prettier_process() {
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
formatter_clangformat_supports() {
case "$1" in
.c|.cpp|.cxx|\
.h|.hpp|\
.m)
return 0;;
esac
return 1
}
formatter_clangformat_process() {
clang-format "$1" 2>/dev/null
return $?
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
formatter_rustfmt_supports() {
[[ "$1" = ".rs" ]]
return $?
@ -135,6 +153,7 @@ process_file() {
fi
local formatter="$(map_extension_to_formatter "$fext")"
echo "FORMATTER >>> $formatter"
if [[ "$formatter" = "none" ]]; then
if [[ -z "$OPT_LANGUAGE" ]]; then
print_file "$file"