-
-
Save c-nv-s/885b8c94c55bea47ccfd55266e8739ea to your computer and use it in GitHub Desktop.
Cross-app URL aliases (like shell aliases) powered by Nginx.
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
#!/usr/bin/env bash | |
# All my gist code is licensed under the MIT license. | |
# Video demo: https://www.youtube.com/watch?v=y542zPAPeG4¡™£ | |
# colorcat | |
# - cats a file, but if any line contains N hex colors, it appends the colors | |
# (rendered as ansi escape sequences) to the end of the line. | |
# - input can be stdin, a file, or a hex color in plain text | |
if [[ "$#" -eq 1 && ! -f "$1" ]]; then | |
echo "$1" | |
else | |
cat "$@" | |
fi | while read -r line; do | |
local colors="" | |
for word in $line; do | |
if [[ "$word" =~ ^[^A-Fa-f0-9]*#?([A-Fa-f0-9]{6})[^A-Fa-f0-9]*$ ]]; then | |
hex=${BASH_REMATCH[1]} | |
local r=$((16#${hex:0:2})) | |
local g=$((16#${hex:2:2})) | |
local b=$((16#${hex:4:2})) | |
local truecolor="\033[48;2;${r};${g};${b}m" | |
local reset="\033[0m" | |
colors="${colors}${truecolor} ${reset} " | |
fi | |
done | |
echo -e "$line $colors" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment