Skip to content

Instantly share code, notes, and snippets.

@HusseinMorsy
Created March 18, 2012 00:33
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HusseinMorsy/2067034 to your computer and use it in GitHub Desktop.
Save HusseinMorsy/2067034 to your computer and use it in GitHub Desktop.
script for pomodoro timer with tmux and Pomodoro-App
#!/usr/bin/env ruby
#
# for use with ugol's pomodoro app (https://github.com/ugol/pomodoro) and tmux
# use applescript to set the time
# How to use it:
# 1. Open preferences from the pomodoro app
# 2. Choose script
# 3. Set start, reset and end to: do shell script "/usr/local/bin/pomodoro reset"
# 4. set every 1 min to: do shell script "/usr/local/bin/pomodoro decrease"
# 5. in .tmux.conf set set -g status-right "#(date '+%H:%M') | #(~/bin/pomodoro time) min"
class Pomodoro
TIME_FILE = File.expand_path('~/.pomodoro_left_time')
attr_accessor :time_file
def initialize(time_file=TIME_FILE)
@time_file = time_file
end
def reset_timer(value=25)
write_time_to_file(value-1)
end
def current_time
read_time_from_file
end
def decrease(step=1)
new_time = current_time-1
write_time_to_file(new_time)
end
def read_time_from_file
time = nil
f = File.open(@time_file) do |f|
time = f.read.to_i
end
time
end
def write_time_to_file(value)
f = File.open(@time_file, "w") do |f|
f.write(value)
end
value
end
end
command = ARGV.shift || 'time'
p = Pomodoro.new
case command
when 'time'
puts p.current_time
when 'decrease'
p.decrease
when 'reset'
p.reset_timer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment