Handle multiple input file arguments as well as - for standard input

This commit is contained in:
2022-03-05 16:59:12 +01:00
parent 4fbb7ec04d
commit dd426b16d5

View File

@@ -260,23 +260,36 @@ parseline() {
} }
catmd() { catmd() {
local line=
for arg in "$@"; do for arg in "$@"; do
case "$1" in case "$1" in
-)
# treat - as input stream
break;;
-*) -*)
# Ignore args for now # Ignore args for now
shift;; shift;;
esac esac
done done
local file="$1"
local line=
local myargs=("$@")
# 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 while IFS='' read -r line; do
parseline "$line" parseline "$line"
done <"${file:-/dev/stdin}" done <"${file}"
# If last line in a file has no newline, read ends but still populates $line
[[ $line ]] && parseline "$line"
echo -en "$FO_RESET" echo -en "$FO_RESET"
done
} }
## Font formating ## Font formating
FO_RESET=$(tput sgr0)
FO_BLINK=$(tput blink) # '\033[5m' FO_BLINK=$(tput blink) # '\033[5m'
FO_BOLD=$(tput bold) # '\033[1m' FO_BOLD=$(tput bold) # '\033[1m'
FO_SO=$(tput smso) # '\033[7m' FO_SO=$(tput smso) # '\033[7m'
@@ -287,7 +300,6 @@ FO_INVIS=$(tput invis) # '\033[8m'
## Rareley supported ## Rareley supported
FO_DIM=$(tput dim) FO_DIM=$(tput dim)
FO_REV=$(tput rev) FO_REV=$(tput rev)
FO_RESET=$(tput sgr0)
## Colorcodes ## Colorcodes
## ##