Last active
May 29, 2018 13:27
-
-
Save pachacamac/f638752ffdbf5e9dcd8944adaa3dafd0 to your computer and use it in GitHub Desktop.
reminder script in ruby
This file contains hidden or 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 '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