Reply To: CLI World Clock mini script

Forum › Forums › General › Tips and Tricks › CLI World Clock mini script › Reply To: CLI World Clock mini script

#74965
PPC
Member

    Thanks, everyone!

    I have a slightly updated version, that also shows local time (I noticed I was always looking at my toolbar to see what time it was here). Also I shortned the instructions, to make them more practical, and removed the empty final line that crept into the config file:

    #!/bin/bash
    # Command-line world clock by PPC 9/1/2022, GPL license
    #Adapted from http://gist.github.com/rangersmyth74/4c7e291b64d48c1beb7029e9b07b6bca
    #and from examples over at stackoverflow like over at http://stackoverflow.com/questions/370075/command-line-world-clock
    
    # create preference file $HOME/.world-clock.zones, if it's missing
    if [ ! -f $HOME/.world-clock.zones ]; then
    echo "Europe/London
    Europe/Paris
    Asia/Tokyo
    America/St_Johns
    Brazil/West" > $HOME/.world-clock.zones
    fi
    
    : ${WORLDCLOCK_ZONES:=$HOME/.world-clock.zones}
    : ${WORLDCLOCK_FORMAT:='+%Y-%m-%d %H:%M:%S %Z'}
    
    function world-clock ()
    {
    echo
    echo "		CLI World Clock:"
    echo
    local_time=$(date "$WORLDCLOCK_FORMAT")
    echo "Local Time	       $local_time"
    echo
    
    while read zone
    do echo $zone '!' $(TZ=$zone date "$WORLDCLOCK_FORMAT")
    done < $WORLDCLOCK_ZONES |
    awk -F '!' '{ printf "%-20s  %s\n", $1, $2;}' |
    sort -b -r -k2,2 -k3,3
    echo
    echo "To manage the time zones, edit the file $HOME/.world-clock.zones"
    echo "All time zones are listed at http://en.wikipedia.org/wiki/List_of_tz_database_time_zones"
    echo
    echo "Press Ctrl + C to exit"
    }
    
    export -f world-clock
    clear
    
    while true;
    do
    	world-clock;
    	sleep 1;
    	clear
    done
    

    @sleekmason – nice plug for your build! Myself, I find antiX full, with my FT10 transformation pack perfect in every single device I tested (from an 32bits/1Gig of RAM laptop to my quad-core, 4Gig desktop)

    P.

    • This reply was modified 4 years, 8 months ago by PPC.