-
-
Save pdxmph/93fcc5122063e7b364cd0a992e25753a to your computer and use it in GitHub Desktop.
Use gcalcli to quickly schedule work blocks.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'active_support/all' | |
require 'optparse' | |
require 'optparse/date' | |
options = {} | |
title = ARGV[0] | |
OptionParser.new do |parser| | |
parser.banner = "Usage: sked 'item name' [options]" | |
parser.on("-t", "--time TIME", "The time the block should start, e.g. 13:00") do |o| | |
options[:time] = Time.parse(o) | |
end | |
parser.on("-d", "--duration DURATION", "How long the block should run in minutes, e.g. 30 (default)") do |o| | |
options[:duration] = o | |
end | |
parser.on("-D", "--date [date]", Date, "Set date, e.g.2023-01-01, defaults to today") do |o| | |
options[:date] = o | |
end | |
parser.on("-h", "--help", "Get help.") do | |
puts parser | |
exit(0) | |
end | |
end.parse! | |
if options[:duration] | |
duration = options[:duration].to_i | |
end_time = (options[:time] + duration.minutes).strftime("%H:%M") | |
else | |
end_time = (options[:times] + 30.minutes).strftime("%H:%M") | |
end | |
if options[:date] | |
date = options[:date] | |
else | |
date = Date.today.strftime("%Y-%m-%d") | |
end | |
start = options[:time].strftime("%H:%M") | |
begin | |
`gcalcli quick "🚧 #{title} #{date} #{start}-#{end_time}" --reminder '5m popup'` | |
puts "Scheduled: '#{title}' at #{start} on #{date}. It will end at #{end_time}." | |
rescue | |
puts "Something went wrong." | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment