Source code
#!/usr/bin/env bash
if [[ "$#" -eq 1 && ! -f "$1" ]]; then
echo "$1"
else
cat "$@"
fi | while read -r line; do
colors=""
for word in $line; do
if [[ "$word" =~ ^[^A-Fa-f0-9]*
hex=${BASH_REMATCH[1]}
r=$((16#${hex:0:2}))
g=$((16#${hex:2:2}))
b=$((16#${hex:4:2}))
truecolor="\033[48;2;${r};${g};${b}m"
reset="\033[0m"
colors="${colors}${truecolor} ${reset} "
fi
done
echo -e "$line $colors"
done
This should definitely be in
bat
Good idea, I opened a feature request