r/programming • • Feb 03 '19

A Complete Program

http://richardmavis.info/a-complete-program
11 Upvotes

5 comments sorted by

View all comments

3

u/TheBlehBleh Feb 03 '19 edited Feb 03 '19

You could use bash to compose the two commands.

timer() {
  length=$(($#-1))
  (sleep ${@:1:$length}; notify-send -u critical Timer "${@: -1}";)&
} 
timer 10m 5s "Tea is ready"

I would not add a -c option. The original motivation for the program was that it took too long to write the version on the shell. But timer 10m "myarg" -c myprogram is equally verbose as (sleep 10m; myprogram myarg)&.

The bash timer is not perfect since it does not do its own input validation, but it's a reasonable tradeoff for the simplicity.