-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpom
executable file
·94 lines (85 loc) · 2.78 KB
/
pom
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/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