Add python formatter black to prettybat

This commit is contained in:
Jeremy Paige 2020-12-16 10:03:36 -08:00 committed by Ethan P
parent eb69d61ff8
commit 165fc69d34
2 changed files with 23 additions and 1 deletions

View File

@ -35,6 +35,7 @@ See `man bat` for more information.
| 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) |
| Python | [black](https://black.readthedocs.io/) |

View File

@ -21,7 +21,7 @@ hook_version
# Formatters:
# -----------------------------------------------------------------------------
FORMATTERS=("prettier" "rustfmt" "shfmt" "clangformat")
FORMATTERS=("prettier" "rustfmt" "shfmt" "clangformat" "black")
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -90,6 +90,26 @@ formatter_shfmt_process() {
return $?
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
formatter_black_supports() {
case "$1" in
.py | \
.py3 | \
.pyw | \
.pyi)
return 0
;;
esac
return 1
}
formatter_black_process() {
black --code "$(cat -)"
return $?
}
# -----------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------
@ -115,6 +135,7 @@ map_language_to_extension() {
yaml | yml) ext=".yml" ;;
rust | rs) ext=".rs" ;;
graphql | gql) ext=".graphql" ;;
python | py) ext=".py" ;;
esac
echo "$ext"