Advertisement
howtophil

Remind yourself to do something every X minutes (bash)

Jul 4th, 2018
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.04 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #------------------------------------------------------------------------
  4. #
  5. # A simple script to remind you do something
  6. # every X number of minutes. It uses espeak
  7. # to tell you a message then waits for a
  8. # space bar to start the timer again.
  9. #
  10. # ctrl-c exits
  11. #
  12. # ./doeveryxminutes.sh [minutes integer] "Message to self string"
  13. #
  14. # Hope you ejoy,
  15. #    Phillip J Rhoades
  16. #
  17. #------------------------------------------------------------------------
  18.  
  19. # Initialize some things
  20. xminutes=$1
  21. themessage="$2"
  22.  
  23. ###
  24.  
  25. tput civis #hide the cursor
  26.  
  27. #Bring the cursor back after ctrl-c
  28. trap ctrl_c INT
  29. function ctrl_c() {
  30.         tput cvvis
  31.     exit
  32. }
  33.  
  34. #Loop those minutes
  35. while [ 1 ]; do
  36.     secs=$(($xminutes * 60))
  37.     while [ $secs -gt -1 ]; do
  38.         theminutes=$(printf "%02d" $((m=(${secs}%3600)/60)))
  39.         theseconds=$(printf "%02d" $((s=${secs}%60)))
  40.         echo -ne "Countdown to \"$themessage\": $theminutes:$theseconds\033[0K\r"
  41.         sleep 1
  42.         : $((secs--))
  43.     done
  44.     echo $themessage |espeak >/dev/null
  45.     echo -ne "Press space to continue...\033[0K\r"
  46.     read -n1 -r -p "" key
  47.  
  48. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement