Skip to content

Instantly share code, notes, and snippets.

@vivien
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vivien/9529717 to your computer and use it in GitHub Desktop.
Save vivien/9529717 to your computer and use it in GitHub Desktop.
Script to toggle timezones in i3blocks
#!/bin/ruby
#
# Toggle timezones in i3blocks
# Author: Vivien Didelot <vivien.didelot@gmail.com>
#
# Fill the ZONES array and define a block like this:
#
# [timezone]
# command=THIS_SCRIPT
# interval=5
ZONES = [
"America/Montreal",
"Pacific/Noumea",
"Europe/Paris",
]
CACHE = "/tmp/tz"
def datetime zone, format
%x(TZ=#{ zone } date '+#{ format }')
end
def get_timezone
zone = ZONES.first
# toggle on click
if ENV["BLOCK_BUTTON"].to_i > 0
if File.exist? CACHE
cached = File.read(CACHE)
zone = cached if ZONES.include? cached
end
index = ZONES.index(zone) || -1
index = (index + 1) % ZONES.size
zone = ZONES[index]
# cache the timezone
File.open(CACHE, 'w') { |f| f.write(zone) }
end
zone
end
zone = get_timezone
city = zone.split('/').last
full_text = "#{ city }: #{ datetime(zone, "%D %T") }"
short_text = "#{ city.chars.first }: #{ datetime(zone, "%T") }"
color = "#00FF00"
# output the block
puts full_text
puts short_text
puts color
# vim: ts=2 sw=2 et
Copy link

ghost commented Aug 19, 2015

Hey @vivien,

In case you haven't heard, i3blocks is splitting into two repos! i3blocks will now go on to contain the core binary and a set of smallest usable blocklets to provide some beginner functionality. From i3blocks, i3blocks-contrib has now split off to gather the community contributed blocklets in a single repo to make perusing them easier and more convenient. We would be honoured if you would consider submitting your blocklet(s) to the contrib repo.

This change is the core change scheduled for the v1.5 release. Please note that as an artifact of this split, your entry for this blocklet in the core wiki has been removed as has everyone else's. If you would like to submit your blocklet, please review the contrib wiki to understand the workflow of i3blocks-contrib.

Please note that this change over is in its early stages, so the process for submission hasn't been completely nailed down. We're hard at work still compiling the two project wikis and documenting all changes and standards. It is very likely that things will still change and we value your input on how that change should occur.

Deepest regrads,

@Nycroth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment