94 lines
2.8 KiB
Ruby
Executable file
94 lines
2.8 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
|
|
require 'date'
|
|
require 'rainbow'
|
|
require 'terminal-notifier'
|
|
require_relative 'lib/task'
|
|
require_relative 'lib/countdown'
|
|
require_relative 'lib/pomo_logger'
|
|
require_relative 'lib/terminal_notifier_logger'
|
|
require_relative 'lib/file_logger'
|
|
|
|
POMODORO_SECONDS = 25 * 60
|
|
# TODO: either move this to a env variable or a yml configuration file
|
|
POMODORO_LOG_FILE = "#{ENV['HOME']}/Documents/pomodoro_log.txt"
|
|
|
|
def logger
|
|
PomoLogger.new(
|
|
:pomodoro_log_file => POMODORO_LOG_FILE
|
|
)
|
|
end
|
|
|
|
def read_todos
|
|
todos = File.read(ENV['TODO_FILE'])
|
|
todos.split(/\r?\n/)
|
|
end
|
|
|
|
def increase_pomos todos, index
|
|
todo_to_update = todos[index]
|
|
task = Task.new(index + 1, todo_to_update)
|
|
task.add_pomo
|
|
task.puts_highlighted
|
|
`todo.sh replace #{index + 1} "#{task.to_s}"`
|
|
end
|
|
|
|
def plan_task todos, index, planned
|
|
todo_to_update = todos[index]
|
|
task = Task.new(index + 1, todo_to_update)
|
|
task.plan(planned)
|
|
task.puts_highlighted
|
|
`todo.sh replace #{index + 1} "#{task.to_s}"`
|
|
end
|
|
|
|
def puts_and_exit string
|
|
puts string
|
|
exit
|
|
end
|
|
|
|
|
|
case ARGV[1]
|
|
when 'ls'
|
|
todos = read_todos
|
|
todos.each_with_index do |todo, index|
|
|
Task.new(index + 1, todo).puts_highlighted
|
|
end
|
|
when 'log'
|
|
puts `cat #{POMODORO_LOG_FILE}`
|
|
when 'add'
|
|
puts_and_exit "You must insert the task number" unless index = ARGV[2]
|
|
puts_and_exit "Task number must be... a number" unless index =~ /\d+/
|
|
index = index.to_i - 1
|
|
todos = read_todos
|
|
increase_pomos todos, index
|
|
when 'plan'
|
|
puts_and_exit "You must insert the task number" unless index = ARGV[2]
|
|
puts_and_exit "Task number must be... a number" unless index =~ /\d+/
|
|
puts_and_exit "You must insert the task pomodori estimate" unless planned = ARGV[3]
|
|
puts_and_exit "The task pomodori estimate must be a number" unless planned =~ /\d+/
|
|
index = index.to_i - 1
|
|
todos = read_todos
|
|
plan_task todos, index, planned
|
|
when 'start'
|
|
puts_and_exit "You must insert the task number" unless index = ARGV[2]
|
|
puts_and_exit "Task number must be... a number" unless index =~ /\d+/
|
|
index = index.to_i - 1
|
|
todos = read_todos
|
|
task_being_worked = Task.new(index + 1, todos[index])
|
|
logger.log_pomodoro_started(task_being_worked)
|
|
Countdown.new.run(POMODORO_SECONDS, services: [ :tmux, :iterm2 ])
|
|
logger.log_pomodoro_completed(task_being_worked)
|
|
increase_pomos todos, index
|
|
when 'help'
|
|
puts "Usage: todo.sh pomo action [task_number] [args]\n"
|
|
puts "Actions:"
|
|
puts " ls"
|
|
puts " lists tasks with pomodori count and estimates"
|
|
puts " log"
|
|
puts " displays a log of your pomodori"
|
|
puts " start ITEM#"
|
|
puts " start a pomodoro timer for item ITEM#"
|
|
puts " add ITEM#"
|
|
puts " add one pomodoro to task on line ITEM# without running a timer"
|
|
puts " plan ITEM# PLANNED_POMODORI"
|
|
puts " estimate ITEM# will take PLANNED_POMODORI to complete"
|
|
end
|