Handle multiple input file arguments as well as - for standard input
This commit is contained in:
20
catmd.sh
20
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=("$@")
|
||||
|
||||
# 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:-/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"
|
||||
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
|
||||
##
|
||||
|
Reference in New Issue
Block a user