From dd426b16d5e03a164597206b7db16577f274faad Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Sat, 5 Mar 2022 16:59:12 +0100 Subject: [PATCH] Handle multiple input file arguments as well as - for standard input --- catmd.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/catmd.sh b/catmd.sh index fadee5e..c682b90 100755 --- a/catmd.sh +++ b/catmd.sh @@ -260,23 +260,36 @@ parseline() { } catmd() { - local line= for arg in "$@"; do case "$1" in + -) + # treat - as input stream + break;; -*) # Ignore args for now shift;; esac done - local file="$1" + + local line= + local myargs=("$@") - while IFS='' read -r line; do - parseline "$line" - done <"${file:-/dev/stdin}" - echo -en "$FO_RESET" + # Use standard input if now files are present + [ $# -eq 0 ] && myargs[0]="/dev/stdin" + + for file in "${myargs[@]}"; do + [ "$file" == "-" ] && file="/dev/stdin" + while IFS='' read -r line; do + parseline "$line" + done <"${file}" + # If last line in a file has no newline, read ends but still populates $line + [[ $line ]] && parseline "$line" + echo -en "$FO_RESET" + done } ## Font formating +FO_RESET=$(tput sgr0) FO_BLINK=$(tput blink) # '\033[5m' FO_BOLD=$(tput bold) # '\033[1m' FO_SO=$(tput smso) # '\033[7m' @@ -287,7 +300,6 @@ FO_INVIS=$(tput invis) # '\033[8m' ## Rareley supported FO_DIM=$(tput dim) FO_REV=$(tput rev) -FO_RESET=$(tput sgr0) ## Colorcodes ##