mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-06-20 19:57:46 +02:00
Added rust support to prettybat
This commit is contained in:
parent
16ea5cc401
commit
09604dbefc
@ -10,12 +10,13 @@ source "${LIB}/opt.sh"
|
|||||||
source "${LIB}/str.sh"
|
source "${LIB}/str.sh"
|
||||||
source "${LIB}/print.sh"
|
source "${LIB}/print.sh"
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
PROGRAM="$0"
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Formatters:
|
# Formatters:
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
FORMATTERS=("prettier")
|
FORMATTERS=("prettier" "rustfmt")
|
||||||
|
|
||||||
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
@ -39,6 +40,19 @@ formatter_prettier_process() {
|
|||||||
return $?
|
return $?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
|
formatter_rustfmt_supports() {
|
||||||
|
[[ "$1" = ".rs" ]]
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
formatter_rustfmt_process() {
|
||||||
|
rustfmt
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
# Functions:
|
# Functions:
|
||||||
# -----------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------
|
||||||
@ -62,6 +76,7 @@ map_language_to_extension() {
|
|||||||
json) ext=".json" ;;
|
json) ext=".json" ;;
|
||||||
md|mdown|markdown) ext=".md" ;;
|
md|mdown|markdown) ext=".md" ;;
|
||||||
yaml|yml) ext=".yml" ;;
|
yaml|yml) ext=".yml" ;;
|
||||||
|
rust|rs) ext=".rs" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
echo "$ext"
|
echo "$ext"
|
||||||
@ -120,14 +135,14 @@ process_file() {
|
|||||||
data_raw="$(cat -)"
|
data_raw="$(cat -)"
|
||||||
data_formatted="$("formatter_${formatter}_process" "$file" 2>/dev/null <<< "$data_raw")"
|
data_formatted="$("formatter_${formatter}_process" "$file" 2>/dev/null <<< "$data_raw")"
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
printc "{YELLOW}[%s warning]{CLEAR}: 'STDIN': Unable to format with '%s'" "$0" "$formatter" 1>&2
|
printc "%{YELLOW}[%s warning]%{CLEAR}: 'STDIN': Unable to format with '%s'\n" "$PROGRAM" "$formatter" 1>&2
|
||||||
print_file --language="$lang" - <<< "$data_raw"
|
print_file --language="$lang" - <<< "$data_raw"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
data_formatted="$("formatter_${formatter}_process" "$file" < "$file")"
|
data_formatted="$("formatter_${formatter}_process" "$file" < "$file")"
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
printc "{YELLOW}[%s warning]{CLEAR}: '%s': Unable to format with '%s'" "$0" "$file" "$formatter" 1>&2
|
printc "%{YELLOW}[%s warning]%{CLEAR}: '%s': Unable to format with '%s'\n" "$PROGRAM" "$file" "$formatter" 1>&2
|
||||||
print_file --language="$lang" "$file"
|
print_file --language="$lang" "$file"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user