#!/bin/bash

## 🤓 http://crn.hopto.org  Enjoy and God bless! 

# Colors - uncomment if needed
R=$(tput setaf 1)                          # red
BR=$(tput setaf 1; tput bold)              # bold red
G=$(tput setaf 2)                          # green
BG=$(tput setaf 2; tput bold)              # bold green
Y=$(tput setaf 3)                          # yellow
BY=$(tput setaf 3; tput bold)              # bold yellow
B=$(tput setaf 4)                          # blue
BM=$(tput setaf 5; tput bold)              # bold magenta
BC=$(tput setaf 6; tput bold)              # bold cyan
BL=$(tput setaf 7; tput bold)              # bold light grey
BLD=$(tput bold)                           # bold
N=$(tput sgr0)                             # normal
SIT=$(tput sitm)                           # italics
RIT=$(tput ritm)                           # remove italics
UL=$(tput smul)                            # turn underline on
NL=$(tput rmul)                            # turn underline off
RV=$(tput rev)                             # turn on reverse mode
ROWS=$(tput lines)
COLS=$(tput cols)

# set color based on hour
[[ $(date +%-H) -gt 0 ]] && COLOR="$BG"
[[ $(date +%-H) -gt 11 ]] && COLOR="$BY"
[[ $(date +%-H) -gt 19 ]] && COLOR="$BR"

# calculate % of year past
part="$(date +%j)"
total=365
PERCENT=$(( (part * 100) / total ))

# main loop
while true; do
  now=$(date +%s)
  start=$(date -d "today 00:00:00" +%s)
  elapsed=$((now - start))
  total=86400
  pct=$((elapsed * 100 / total))
  bars=$((pct * 50 / 100))
  echo -n "$BLD"
  printf "\r🕒 %(%-r)T %d%% |" -1 "$pct"
  echo -n "$N"
  for ((i=0; i<50; i++)); do
    if ((i < bars)); then
      printf "${COLOR}â–ˆ${N}"
    elif ((i % 5 == 0)); then
      printf "|"
    else
      printf "â–‘"
    fi
  done
  if [[ $# -eq 0 ]]
  then
      sleep 1
  else
      echo " "
      #echo " 📆 ${BLD}$(date +"%x 📊 $PERCENT%%")${N}"
      exit
  fi
done