Thursday, October 3, 2019

View File Hex Colors

You can cd to a directory where files with 0x prefixed colors are located and display them side by side their matching context.
alias vc='_(){ local file=${1:-blah};(($#<1))||[[ "${1}" =~ ^- ]]&&echo "Usage: vc <file>"&&return 1;[[ ! -e "${file}" ]]&&echo "File ${file} not found."&&return 1; echo "${file}:";paste <(for a in $(grep -Po "(?<=\b0x)[[:xdigit:]]{6}\b" "${file}"); do perl -e "foreach \$a(@ARGV){print \"\e[48;2;\".join(\";\",unpack(\"C*\",pack(\"H*\",\$a))).\"m \e[49m \"};print \"\n\"" "$a"; done) <(grep -P "(?<=\b0x)[[:xdigit:]]{6}\b" "${file}");}; _' 
E.g. cd ~/.config/alacritty/colors;for a in *yml; do vc "$a"; done

Get a more robust version on GitHub.

No comments:

Post a Comment