Skip to content

Instantly share code, notes, and snippets.

@pachacamac
Last active May 29, 2018 13:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pachacamac/f638752ffdbf5e9dcd8944adaa3dafd0 to your computer and use it in GitHub Desktop.
Save pachacamac/f638752ffdbf5e9dcd8944adaa3dafd0 to your computer and use it in GitHub Desktop.
reminder script in ruby
#!/usr/bin/env ruby
require 'chronic'
require 'time'
require 'securerandom'
abort('notify-send not installed') if `which notify-send`.empty?
ts = ARGV.join(' ')
t = Chronic.parse(ts)
abort("'#{ts}' not understood") unless t
puts "What should I remind you about at #{t.strftime('%D %R')}?"
print '> '
msg = STDIN.gets.chomp.gsub("'",'"')
tmp_name = "/tmp/#{t.iso8601.gsub(/\W/,'_')}_#{SecureRandom.uuid}"
File.write tmp_name, <<-EOS
#!/usr/bin/env ruby
loop do
if Time.now.to_i >= #{t.to_i}
`notify-send -i /usr/share/icons/Humanity/status/128/info.svg -u critical '#{msg}'`
File.delete('#{tmp_name}')
exit
else
sleep 2
end
end
EOS
puts [
'sure thing!',
'will do :)',
'no problem!',
'okilly dokilly'
].sample
`nohup ruby #{tmp_name} >/dev/null 2>&1&`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment