Created
May 12, 2021 20:08
-
-
Save Daniel-Abrecht/371f3099e420014c67dc67cf5248967a to your computer and use it in GitHub Desktop.
Colors matched lined such that the same matches have the same color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
pattern="$1" | |
while IFS= read -r line | |
do | |
if ! matchpart="$(grep -o "$pattern" <<<"$line")" | |
then printf "%s\n" "$line"; continue | |
fi | |
rstr="$(printf "%s\n" "$matchpart" | head -n 1 | md5sum | head -c 6)" | |
rgb=( $((echo 'ibase=16'; echo "${rstr^^}" | grep -o '..' | sed 's|.*| ( \0 + 10 ) * 10 / 11 |') | bc) ) | |
printf '\033[38;2;%d;%d;%dm%s\033[0m\n' "${rgb[0]}" "${rgb[1]}" "${rgb[2]}" "$line" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment