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}/print.sh"
source "${LIB}/version.sh" source "${LIB}/version.sh"
source "${LIB}/check.sh" source "${LIB}/check.sh"
source "${LIB}/term.sh"
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
# Init: # Init:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -22,7 +23,10 @@ hook_version
# Formatters: # 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 $? 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: # Functions:
# ----------------------------------------------------------------------------- # -----------------------------------------------------------------------------
@ -167,6 +198,7 @@ map_language_to_extension() {
python | py) ext=".py" ;; python | py) ext=".py" ;;
elixir | ex) ext=".ex" ;; elixir | ex) ext=".ex" ;;
exs) ext=".exs" ;; exs) ext=".exs" ;;
tsv) ext=".tsv" ;;
esac esac
echo "$ext" echo "$ext"
@ -294,6 +326,8 @@ OPT_LANGUAGE=
FILES=() FILES=()
DEBUG_PRINT_FORMATTER=false DEBUG_PRINT_FORMATTER=false
TERMINAL_WIDTH="$(term_width)"
# Parse arguments. # Parse arguments.
while shiftopt; do while shiftopt; do
case "$OPT" in case "$OPT" in