#!/bin/zsh setopt no_unset warn_create_global extended_glob zmodload zsh/datetime || exit $? cd /mnt/container-logs || exit $? #exec tail -f "$@" */current(Om) | s6-tai64nlocal prompt_hash_color_zshrc() { local h c # djbhash, simple string hash function to generate distinct numbers for similar strings h=5381 for c in ${(s::)1}; do h=$(( ( (h << 5) + h + #c ) % 0xffffffff )) done local -a color_list # List of colors bright enough to be readable against dark background if (($+FG_COLOR_NUMBERS)); then color_list=( $=FG_COLOR_NUMBERS ) elif [[ $terminfo[colors] == 256 ]]; then color_list=( 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 ) else color_list=( 1 2 3 5 6 7 9 10 11 13 14 15 ) fi printf '%%F{%d}' $color_list[$h%$#color_list+1] } typeset -g fg_reset=%f typeset -gA cached_hash_colors colored cache_hash_color() { local i fg_color for i in "$@"; do (( $+colored[$i] )) && continue fg_color=$(prompt_hash_color_zshrc $i) cached_hash_colors[$i]=${(%)fg_color} colored[$i]=${(%)fg_color}$i${(%)fg_reset} done } typeset -gA hour_colors=( 00 40 01 40 02 47 03 82 04 118 05 154 06 190 07 226 08 227 09 228 10 229 11 230 12 231 13 231 14 230 15 229 16 228 17 227 18 226 19 190 20 154 21 118 22 82 23 47 ) typeset -gA dow_colors=( 1 1 # Monday -> Red (maroon) 2 3 # Tuesday -> Yellow (olive) 3 2 # Wednesday -> Green 4 6 # Thursday -> Cyan (teal) 5 4 # Friday -> Blue (navy) 6 5 # Saturday -> Magenta (purple) 0 7 # Sunday -> White (silver) ) main() { local D T H line Dcolored Tcolored Tfract color digits i ts dow /mnt/ns/bin/mlog -f */current(Om) | s6-tai64nlocal | while read D T H line; do H=${${H#container.}%.$USER} cache_hash_color $H strftime -r -s ts '%Y-%m-%d' $D strftime -s dow '%w' $ts color="%F{${dow_colors[$dow]:-9}}" Dcolored=${(%)color}$D${(%)fg_reset} Tfract=${T#${T%%.*}} T=${T%%.*} color="%F{${hour_colors[${T%%:*}]:-196}}" Tcolored=${(%)color}${T%%.*}${(%)fg_reset}${T#${T%%.*}} digits=$#Tfract ((digits > 6)) && digits=6 for i in {1..$digits}; do color="%F{$(( 255 - (i-1) * 4 ))}" Tcolored+=${(%)color}$Tfract[$i] done Tcolored+=${(%)fg_reset} printf '%s\n' "$Dcolored $Tcolored [$colored[$H]] $line" done } main