Forum › Forums › General › Tips and Tricks › CLI World Clock mini script
- This topic has 12 replies, 5 voices, and was last updated Jan 10-10:58 pm by sleekmason.
-
AuthorPosts
-
January 9, 2022 at 6:39 pm #74897Member
PPC
I was looking to adapt a nice little GUI World Clock to include in my FT10. I still have not created such a script, but I managed to create a nice little one that Works in the terminal.
-Copy the text below to a text document called something like “world-clock.sh” and save it
-make sure the script is executable
-run the script from the terminalNote: the script automatically creates the needed config file, that can be edited, and includes all needed instructions.
#!/bin/bash # Command-line world clock by PPC 9/1/2022, GPL license #Adapted from https://gist.github.com/rangersmyth74/4c7e291b64d48c1beb7029e9b07b6bca #and from examples over at stackoverflow like over at https://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 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 "You can manage the displayed time zones by editing the file $HOME/.world-clock.zones" echo "The list of all available time zones, in English, is available at https://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 doneEnjoy
P.- This topic was modified 1 year, 3 months ago by PPC.
January 9, 2022 at 7:10 pm #74900Moderator
christophe
January 9, 2022 at 9:33 pm #74911Moderator
Brian Masinick
::I agree, very cool! I changed the London time to America/New-York and kept the others intact, so I have several, including UTC, which I believe is the same as London time anyway. Works great!
--
Brian MasinickJanuary 10, 2022 at 3:18 pm #74962Member
sleekmason
::Love this:) Thinking about adding a right-click option in Lilidog for this. Good stuff. My wife and I are always trying to remember time zones of folks we know.
January 10, 2022 at 3:41 pm #74965MemberPPC
::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 https://gist.github.com/rangersmyth74/4c7e291b64d48c1beb7029e9b07b6bca #and from examples over at stackoverflow like over at https://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 https://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 1 year, 3 months ago by PPC.
January 10, 2022 at 4:52 pm #74967Member
sleekmason
::@PPC
Not plugging anything, but thanks. If I were, I would just make announcements. In fact, I have not even updated the original announcement I made in the section designed for such purposes even though it has gone through drastic changes.It seems I have made an error in how freely I can write/think. I certainly won’t discuss Lilidog or anything related anymore and I will remove access to “My build” in my signature. Sorry if I offended anyone by providing the link.
I’ve used antiX since it’s inception, and it is one of two distros I regularly depend on for good advice. I’ve no doubt it runs well on everything you have.
January 10, 2022 at 4:54 pm #74968MemberPPC
::@sleekmason – You missunderstood me! I was happy to see the screenshots from another tinkerer like me!
Now and then I mention my FT10 transformation pack in other threads, other than the official one, when I think it makes sense. you simply said you were thinking about adding this script to your distro, I’m even flatered!P.
- This reply was modified 1 year, 3 months ago by PPC.
January 10, 2022 at 5:07 pm #74971Member
sleekmason
::@sleekmason – You missunderstood me! I was happy to see the screenshots from another tinkerer like me!
Now and then I mention my FT10 transformation pack in other threads, other than the official one, when I think it makes sense. you simply said you were thinking about adding this script to your distro, I’m even flatered!P.
Oh good! I am relieved. Thank you:) I didn’t want to give up coming here:)
January 10, 2022 at 5:52 pm #74973Member
sleekmason
::Would it be possible to change out Ctrl +C? to exit with something like:
echo $'\n\nPress any key to close.'; read -srn1My thinking is to put it as a right-click option on the panel clock, with a simple ‘Press any key to close’.
My brilliant scripting ability of replace it until it works, didn’t. 🙂
January 10, 2022 at 9:25 pm #74985Memberseaken64
::@sleekmason, I don’t think you have to worry about plugging your builds. I’m not an admin here, and Brian or others will correct me if I am wrong, but we did not take any offense. We are all tinkerers and are often interested in what others are doing to modify their systems. A casual mention of a project in context is not a problem.
Seaken64
January 10, 2022 at 10:41 pm #74990MemberPPC
::Would it be possible to change out Ctrl +C?
Sure, I poked around some examples on-line and adapted the script- it now runs on even fewer resources and you can press any key (or the middle mouse button) to exit:
Here:
#!/bin/bash # Command-line world clock by PPC 10/1/2022, GPL license #Adapted from https://gist.github.com/rangersmyth74/4c7e291b64d48c1beb7029e9b07b6bca #and from examples over at stackoverflow like over at https://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 worldtz () { : ${WORLDCLOCK_ZONES:=$HOME/.world-clock.zones} : ${WORLDCLOCK_FORMAT:='+%Y-%m-%d %H:%M:%S %Z'} 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 https://en.wikipedia.org/wiki/List_of_tz_database_time_zones" echo echo "Press any key to exit" #sleep 1; } export -f worldtz watch -t -n 1 -x bash -c worldtz & # put function in the background read -n 1 kill $! # kill the the job most recently placed into the background read -t 0.1 -n 1000000January 10, 2022 at 10:42 pm #74991Moderator
Brian Masinick
::@sleekmason, I don’t think you have to worry about plugging your builds. I’m not an admin here, and Brian or others will correct me if I am wrong, but we did not take any offense. We are all tinkerers and are often interested in what others are doing to modify their systems. A casual mention of a project in context is not a problem.
Seaken64
You’re right. Simple mention of another distribution is fine; we even have a section to discuss experience with variations or rebuilds and reviews.
That would be a good place to discuss other things.
--
Brian MasinickJanuary 10, 2022 at 10:58 pm #74993Member
sleekmason
::Thanks all:)
@PPC Cool! Thank you for taking the time to adjust your script! Nicely done:) -
AuthorPosts
- You must be logged in to reply to this topic.