udate_check.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/bin/sh
  2. ## This is my (demuredemeanor) polybar script for checking time and date, and handling UTC.
  3. ## This script allows me to toggle between my TZ and UTC.
  4. ## It is written to allow an i3 binding to toggle too.
  5. ## The following is a two state awk toggle:
  6. ## awk -v TEMP=/tmp/i3_polybar_utc_${USER} 'BEGIN {{FILE=getline < TEMP < 0 ? "0" : "1"} {if($0==1){STATE=1} else {STATE=0}} {if(STATE==0){system("echo 1 > "TEMP)} else {system("echo 0 > "TEMP)}} }'
  7. ## Store toggle status
  8. UTC_TOGGLE="$(cat /tmp/i3_polybar_utc_${USER} 2>/dev/null)"
  9. TZ_TIME="$(date '+%H:%M')"
  10. TZ_DATE="$(date '+%a %d %b')"
  11. UTC_TIME="$(date -u '+%H:%M UTC')"
  12. UTC_DATE="$(date -u '+%F')"
  13. ## Set time output based on toggle status
  14. if [ "${UTC_TOGGLE}" = 1 ]; then
  15. TIME="${UTC_TIME}"
  16. DATE="${UTC_DATE}"
  17. else
  18. TIME="${TZ_TIME}"
  19. DATE="${TZ_DATE}"
  20. fi
  21. ## Format for bar
  22. ## NOTE: there is a literal space at the end due to a current bug with the %{O} format
  23. STATUS="%{B#454A4F F#282A2E}%{B#282A2E F#979997}%{O2}%{O2}%{F#C5C8C6}${DATE}%{O2}%{F#B5BD68}%{B#B5BD68 F#282A2E}%{O2}%{O2}${TIME}%{O4}"
  24. ## Return results
  25. echo "${STATUS}"