Skip to content

Instantly share code, notes, and snippets.

@Daniel-Abrecht
Created May 12, 2021 20:08
Show Gist options
  • Save Daniel-Abrecht/371f3099e420014c67dc67cf5248967a to your computer and use it in GitHub Desktop.
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
#!/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