mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-01-05 20:58:51 +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
|
||||
|
||||
# Check that the file exists, and is a file.
|
||||
check_exists "$file" || return 1
|
||||
check_is_file "$file" || return 1
|
||||
if [[ "$file" != "-" ]]; then
|
||||
check_exists "$file" || return 1
|
||||
check_is_file "$file" || return 1
|
||||
fi
|
||||
|
||||
# Determine the formatter.
|
||||
if [[ -n "$OPT_LANGUAGE" ]]; then
|
||||
@ -190,7 +192,9 @@ process_file() {
|
||||
fext="$(map_language_to_extension "$lang")"
|
||||
fi
|
||||
|
||||
formatter="$(map_extension_to_formatter "$fext")"
|
||||
if [[ "$ext" != "-" ]]; then
|
||||
formatter="$(map_extension_to_formatter "$fext")"
|
||||
fi
|
||||
|
||||
# Debug: Print the name and formatter.
|
||||
if "$DEBUG_PRINT_FORMATTER"; then
|
||||
@ -272,6 +276,9 @@ while shiftopt; do
|
||||
# Debug options
|
||||
--debug:formatter) DEBUG_PRINT_FORMATTER=true ;;
|
||||
|
||||
# Read from stdin
|
||||
-) FILES+=("-") ;;
|
||||
|
||||
# bat options
|
||||
-*) {
|
||||
BAT_ARGS+=("$OPT=$OPT_VAL")
|
||||
|
@ -10,3 +10,16 @@ test:version() {
|
||||
prettybat --version | awk 'FNR <= 1 { print $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