mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-01-23 05:38:39 +01:00
prettybat: Allow reading from pipe (#51)
This commit is contained in:
parent
6497bc04a0
commit
860638715a
@ -181,8 +181,10 @@ process_file() {
|
|||||||
local formatter
|
local formatter
|
||||||
|
|
||||||
# Check that the file exists, and is a file.
|
# Check that the file exists, and is a file.
|
||||||
|
if [[ "$file" != "-" ]]; then
|
||||||
check_exists "$file" || return 1
|
check_exists "$file" || return 1
|
||||||
check_is_file "$file" || return 1
|
check_is_file "$file" || return 1
|
||||||
|
fi
|
||||||
|
|
||||||
# Determine the formatter.
|
# Determine the formatter.
|
||||||
if [[ -n "$OPT_LANGUAGE" ]]; then
|
if [[ -n "$OPT_LANGUAGE" ]]; then
|
||||||
@ -190,7 +192,9 @@ process_file() {
|
|||||||
fext="$(map_language_to_extension "$lang")"
|
fext="$(map_language_to_extension "$lang")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "$ext" != "-" ]]; then
|
||||||
formatter="$(map_extension_to_formatter "$fext")"
|
formatter="$(map_extension_to_formatter "$fext")"
|
||||||
|
fi
|
||||||
|
|
||||||
# Debug: Print the name and formatter.
|
# Debug: Print the name and formatter.
|
||||||
if "$DEBUG_PRINT_FORMATTER"; then
|
if "$DEBUG_PRINT_FORMATTER"; then
|
||||||
@ -272,6 +276,9 @@ while shiftopt; do
|
|||||||
# Debug options
|
# Debug options
|
||||||
--debug:formatter) DEBUG_PRINT_FORMATTER=true ;;
|
--debug:formatter) DEBUG_PRINT_FORMATTER=true ;;
|
||||||
|
|
||||||
|
# Read from stdin
|
||||||
|
-) FILES+=("-") ;;
|
||||||
|
|
||||||
# bat options
|
# bat options
|
||||||
-*) {
|
-*) {
|
||||||
BAT_ARGS+=("$OPT=$OPT_VAL")
|
BAT_ARGS+=("$OPT=$OPT_VAL")
|
||||||
|
@ -10,3 +10,16 @@ test:version() {
|
|||||||
prettybat --version | awk 'FNR <= 1 { print $1 }'
|
prettybat --version | awk 'FNR <= 1 { print $1 }'
|
||||||
prettybat --version | awk 'p{print} /^$/ { p=1 }'
|
prettybat --version | awk 'p{print} /^$/ { p=1 }'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test:read_from_pipe() {
|
||||||
|
description "Test 'prettybat -'"
|
||||||
|
|
||||||
|
assert_equal "ABC" "$(echo "ABC" | prettybat)"
|
||||||
|
assert_equal "ABC" "$(echo "ABC" | prettybat -)"
|
||||||
|
}
|
||||||
|
|
||||||
|
test:read_from_pipe_with_formatter() {
|
||||||
|
description "Test 'prettybat - -lsh'"
|
||||||
|
|
||||||
|
assert_equal "-: shfmt" "$(echo "" | prettybat - -lsh --debug:formatter)"
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user