Skip to content

Instantly share code, notes, and snippets.

@madprops
Created September 1, 2022 09:16
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 madprops/4e38b2225167ad5ae109ad99140fe843 to your computer and use it in GitHub Desktop.
Save madprops/4e38b2225167ad5ae109ad99140fe843 to your computer and use it in GitHub Desktop.
Script to start timers
#!/usr/bin/env ruby
require "open3"
# Get input information using rofi
def get_input(prompt, data)
cmd = "rofi -dmenu -p '#{prompt}'"
stdin, stdout, stderr, wait_thr = Open3.popen3(cmd)
stdin.puts(data)
stdin.close
return stdout.read.strip
end
# Main function
def main()
data_file_name = File.expand_path(File.dirname(__FILE__) + "/timer.data")
data = File.read(data_file_name).strip
if ARGV.length >= 2
title = ARGV[0]
time = ARGV[1..-1].join(" ")
else
title = get_input("Enter Title", data)
if title == ""
exit
end
times = "5m\n10m\n15m\n20m\n30m\n60m"
time = get_input("Enter Time", times)
if time == ""
exit
end
end
n = time.gsub(/[^0-9]/, "").strip.to_i
u = time.gsub(/[0-9]/, "").strip
if u == "m" or u.include?("min")
t = n
elsif u == "s" or u.include?("sec")
t = n / 60
elsif u == "h" or u.include?("hour")
t = n * 60
else
t = n
end
lines = data.split("\n")
lines.delete_if {|x| x == title}
lines.unshift(title)
File.write(data_file_name, lines.join("\n"))
`awesome-client 'Utils.timer("#{title}", #{t})'`
end
# Start here
if __FILE__ == $0
main()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment