prettybat: Add basic support for tsv files

This commit is contained in:
Ethan P. 2024-06-01 15:24:20 -07:00
parent 75c757817f
commit 043d2da964
No known key found for this signature in database
GPG Key ID: B29B90B1B228FEBC

View File

@ -14,6 +14,7 @@ source "${LIB}/str.sh"
source "${LIB}/print.sh"
source "${LIB}/version.sh"
source "${LIB}/check.sh"
source "${LIB}/term.sh"
# -----------------------------------------------------------------------------
# Init:
# -----------------------------------------------------------------------------
@ -22,7 +23,10 @@ hook_version
# Formatters:
# -----------------------------------------------------------------------------
FORMATTERS=("prettier" "rustfmt" "shfmt" "clangformat" "black" "mix_format")
FORMATTERS=(
"prettier" "rustfmt" "shfmt" "clangformat"
"black" "mix_format" "column"
)
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@ -138,6 +142,33 @@ formatter_mix_format_process() {
return $?
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
formatter_column_supports() {
case "$1" in
.tsv)
return 0
;;
esac
return 1
}
formatter_column_process() {
local args=(
-t
-s $'\t'
-c "$TERMINAL_WIDTH"
)
if column --help &>/dev/null; then
# GNU `column`
args+=(--keep-empty-lines)
fi
sed 's/$/\n/' | column "${args[@]}"
}
# -----------------------------------------------------------------------------
# Functions:
# -----------------------------------------------------------------------------
@ -167,6 +198,7 @@ map_language_to_extension() {
python | py) ext=".py" ;;
elixir | ex) ext=".ex" ;;
exs) ext=".exs" ;;
tsv) ext=".tsv" ;;
esac
echo "$ext"
@ -294,6 +326,8 @@ OPT_LANGUAGE=
FILES=()
DEBUG_PRINT_FORMATTER=false
TERMINAL_WIDTH="$(term_width)"
# Parse arguments.
while shiftopt; do
case "$OPT" in