dotfiles/bin/print-epoch

66 lines
1.1 KiB
Text
Raw Normal View History

2022-09-09 10:28:23 -05:00
#!/usr/bin/env bash
COLUMNS=$(tput cols)
digit() {
2022-09-09 12:09:38 -05:00
echo -en "\U1FBF$1 "
2022-09-09 10:28:23 -05:00
}
print-time() {
2022-09-09 12:09:38 -05:00
TIMESTAMP="$1"
for ((i = 0; i < ${#TIMESTAMP}; i++)); do
digit "${TIMESTAMP:i:1}"
done
2022-09-09 10:28:23 -05:00
}
spacing() {
2022-09-09 12:09:38 -05:00
for ((i = 0; i < $1; i++)); do
printf "%s" "-"
done
2022-11-21 09:23:12 -06:00
}
2022-09-09 10:28:23 -05:00
2022-11-21 09:23:12 -06:00
col-len() {
if [[ -z "$2" ]]; then
echo "${#1}"
else
echo "$2"
fi
2022-09-09 10:28:23 -05:00
}
2022-11-21 09:23:12 -06:00
awk-color() {
printf 'BEGIN{
for (colnum = 0; colnum<columns+1; colnum++) {
%s;
r = 255-(i*255/columns);
g = (i*510/columns);
b = (i*255/columns);
if (g>255) g = 510-g;
printf "\\033[38;2;%%d;%%d;%%d;49m" , r,g,b
printf "%%s\\033[0m", substr(s,colnum+1,1);
}
printf "\\n";
}' "$1"
}
color-line() {
awk -v columns="$(col-len "$1" "$2")" -v s="$1" \
"$(awk-color 'i = (columns-colnum);')"
}
2022-09-09 10:28:23 -05:00
2022-11-21 09:23:12 -06:00
color-line-rev() {
awk -v columns="$(col-len "$1" "$2")" -v s="$1" \
"$(awk-color 'i = colnum;')"
}
2022-11-21 09:23:12 -06:00
color-word() {
printf "\033[1;9%dm%s\033[0m" "$((RANDOM % 7 + 1))" "$1"
}
epoch=$(date +'%s')
side=$(spacing $(((COLUMNS - (${#epoch} + 6)) / 2)))
printf "\n%s %s %s\n" \
"$(color-line "$side [")" \
"$(color-word "$epoch")" \
"$(color-line-rev "] $side")"