Skip to content

Instantly share code, notes, and snippets.

@fridim fridim/timezone.rb forked from vivien/timezone.rb
Last active Aug 29, 2015

Embed
What would you like to do?
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 = [
"Europe/Paris",
"America/Montreal",
"Indian/Reunion",
]
CACHE = "/tmp/tz"
def datetime zone, format
%x(TZ=#{zone} date '+#{format}')
end
if File.exist? CACHE
index = File.read(CACHE).to_i
else
index = 0
end
# toggle on click
if ENV["BLOCK_BUTTON"].to_i > 0
# cache the index
index = (index + 1) % ZONES.size
File.open(CACHE, 'w') { |f| f.write(index) }
end
zone = ZONES[index]
city = zone.split('/').last
puts "#{city}: #{datetime(zone, "%Y-%m-%d %T")}"
puts "#{city.chars.first}: #{datetime(zone, "%T")}"
puts "#77FF77"
# vim: ts=2 sw=2 et
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.