Handle multiple input file arguments as well as - for standard input
This commit is contained in:
26
catmd.sh
26
catmd.sh
@@ -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=("$@")
|
||||||
|
|
||||||
while IFS='' read -r line; do
|
# Use standard input if now files are present
|
||||||
parseline "$line"
|
[ $# -eq 0 ] && myargs[0]="/dev/stdin"
|
||||||
done <"${file:-/dev/stdin}"
|
|
||||||
echo -en "$FO_RESET"
|
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
|
## 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
|
||||||
##
|
##
|
||||||
|
Reference in New Issue
Block a user