Skip to content

Instantly share code, notes, and snippets.

@steveodom
Last active August 29, 2015 14:26
Show Gist options
  • Save steveodom/29c459eaeaaaa7607640 to your computer and use it in GitHub Desktop.
Save steveodom/29c459eaeaaaa7607640 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Command line tool to add todos to a list. I use it for what I what to get accomplished in my pomodoro interval.
# The todo list is published as a gist so I have a record of all of them
# add as alias in bash_profile
# alias pomo='cd ~/Documents/projects && ./pomo.rb tasks'
require 'rubygems'
require 'commander/import'
require 'gist'
require 'pry'
program :version, '0.0.1'
program :description, 'saves your todo list goals'
GIST_ID = '29c459eaeaaaa7607640'
GIST_FILE = 'pomodoro.md'
command :do do |c|
c.syntax = 'pomo do [options]'
c.summary = ''
c.description = ''
c.example 'description', 'command example'
c.option '--some-switch', 'Some switch that does something'
c.action do |args, options|
get_tasks()
say("So what do you hope to accomplish in the 40 minutes?")
ary = ask("Separate by commas:", lambda { |str| str.split(/,\s*/) }).each_with_index.map {|s, i| (i+1).to_s + ". " + s}
str = ary.join("\n")
Gist.gist(str, :update => GIST_ID, filename: GIST_FILE)
say("\n")
say("Here are your goals for the next 40 minutes:")
say(str)
say("\n")
say("Got it. Kick ass, Steve.")
end
end
command :tasks do |c|
c.syntax = 'pomo tasks [options]'
c.summary = ''
c.description = ''
c.example 'description', 'command example'
c.option '--some-switch', 'Some switch that does something'
c.action do |args, options|
content = get_tasks()
discussion = Discussion.new(content).prompt
end
end
class Discussion
def initialize(content)
@content = content.split("\n")
end
def complete()
@action = ["1"] if @action.empty?
@action.each {|n| @content.delete_at(n.to_i - 1)}
say("Checked off that task!")
prompt()
end
def ask_for_command
res = ask("Enter command (d, a, x, h): ")
raw = res.split(" ")
@command = raw.shift
@action = raw
end
def prompt()
ask_for_command()
case @command
when "x" then close()
when "d" then complete()
when "a" then add_task()
when "h" then help()
else add_task()
end
end
def help
say("d: check off a task. Example: 'd' - deletes the first one. 'd 1 2' - deletes tasks 1 & 2")
say("a: add a task. Example: a my task")
say("x: save and exit")
end
def add_task()
if @action
num = @content.length
@content.push(@action.join(" "))
say("Added!")
prompt()
end
end
def close()
str = @content.join("\n")
if !str.empty?
Gist.gist(str, :update => GIST_ID, filename: GIST_FILE)
end
say("Here's your updated todo list:")
say("________________________________")
say(str)
say("________________________________")
end
end
def get_tasks()
url = "https://api.github.com/gists/" + GIST_ID
res = Net::HTTP.get_response(URI(url))
json = JSON.parse(res.body)
content = json["files"][GIST_FILE]["content"]
say("Todo List:")
say("\n")
say(content)
say("\n")
content
end

create tag modal

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