#!/usr/bin/env ruby require 'gli' require 'fileutils' require 'csv' require 'date' require 'notifier' require 'doro' # Initialization Process.setproctitle("doro") include GLI::App doro_file = "#{Dir.home}/.doro" program_desc 'A minimalist pomodoro application' version Doro::VERSION subcommand_option_handling :normal arguments :strict # Begin CLI desc 'Displays completed pomodoros' arg_name '*no arguments*' command :list do |c| c.desc 'Number of pomodoros to show' c.default_value 10 c.flag :n c.action do |global_options,options,args| Doro::Entries::display_entries(doro_file: doro_file, num_entries: options[:n]) end end desc 'Begins a pomodoro timer' arg_name '*description of task* (eg. cool task)' command :start do |c| c.desc 'Tag task' c.default_value 'untagged' c.flag :t, type: String c.action do |global_options,options,args| raise "You didn't specify a task" if args.empty? interrupt = false task_name = args.join(' ') start_time = Time.now seconds = 0 ProgressBar.new(task_name, 1500).start Signal.trap("INT") { interrupt = true } 1500.times do break if interrupt == true bar.increment seconds += 1 sleep 1 end print("\r") if interrupt == false Notifier.notify( :image => "logo.png", :title => task_name, :message => "Your timer is up! Take a break!" ) end Doro::Entries::add_entry( doro_file: doro_file, task_name: task_name, minutes: seconds / 60, start_time: start_time, tag: options[:t] ) end end desc 'Begins a break timer' arg_name '*none*' command :break do |c| c.desc 'Long (15 min) break' c.switch :long c.desc 'Set time in minutes' c.default_value 5 c.flag :t, type: Integer c.action do |global_options,options,args| interrupt = false minutes = options[:t] options[:long]? minutes = 15 : nil ProgressBar.new('Break', minutes * 60).start Signal.trap("INT") { interrupt = true } (minutes * 60).times do break if interrupt == true bar.increment sleep 1 end if interrupt == false Notifier.notify( :image => "logo.png", :title => 'Break', :message => "Break time's over! Back to work!" ) end end end pre do |global,command,options,args| FileUtils::touch doro_file unless File.file? doro_file true end post do |global,command,options,args| end on_error do |exception| true end exit run(ARGV)