tron-diasporapsycofr

Chronometer

Feb 19th, 2025 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | Software | 0 0
  1. #!/bin/bash
  2. # USE: ./stopwatch.scr and select an option.
  3. echo
  4. TZ=GMT date +"%d:%m:%Y - %H:%M:%S:$(date +%3N) - %s"
  5. echo
  6. # Menu Function
  7. show_menu() {
  8. echo "Select an option:"
  9. echo "1) Start Chrono for 'Human Biology works and execises (Published on diaspora.psyco.fr/tags/human_biology')"
  10. echo "2) View License"
  11. echo "3) Exit"
  12. }
  13.  
  14. # License Function
  15. show_license() {
  16. echo -e "\n19:02:2025 (1739962099) Copyright (c) Peregrino Alemán Armas"
  17. echo "Permission is hereby granted, free of charge, to any person obtaining"
  18. echo "a copy of this software and associated documentation files (the"
  19. echo "\"Software\"), to deal in the Software without restriction, including"
  20. echo "without limitation the rights to use, copy, modify, merge, publish,"
  21. echo "distribute, sublicense, and/or sell copies of the Software, and to"
  22. echo "permit persons to whom the Software is furnished to do so, subject to"
  23. echo "the following conditions:"
  24. echo
  25. echo "The above copyright notice and this permission notice shall be"
  26. echo "included in all copies or substantial portions of the Software."
  27. echo
  28. echo "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,"
  29. echo "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF"
  30. echo "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND"
  31. echo "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE"
  32. echo "LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION"
  33. echo "OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION"
  34. echo "WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
  35. echo -e "\n"
  36. }
  37.  
  38. # Stopwatch Function
  39. start_stopwatch() {
  40. echo "Chrono 'Race' started. Press '1' to stop."
  41.  
  42. start_time=$(date +%s%3N) # Start time in milliseconds
  43.  
  44. while true; do
  45. current_time=$(date +%s%3N) # Get current time in milliseconds
  46. elapsed=$((current_time - start_time)) # Calculate elapsed time
  47.  
  48. min=$((elapsed / 60000)) # Convert to minutes
  49. sec=$(( (elapsed / 1000) % 60 )) # Convert to seconds
  50. ms=$((elapsed % 1000)) # Get milliseconds
  51.  
  52. printf "\r%02d:%02d:%03d" "$min" "$sec" "$ms" # Print formatted time
  53.  
  54. # Check for keypress to stop stopwatch
  55. read -t 0.01 -n 1 key
  56. if [[ "$key" == "1" ]]; then
  57. echo -e "\nStopped at: $min:$sec:$ms"
  58. return
  59. fi
  60. done
  61. }
  62.  
  63. # Main Menu Loop
  64. while true; do
  65. show_menu
  66. echo ''
  67. read -p " Enter choice: " choice
  68.  
  69. case $choice in
  70. 1) start_stopwatch ;;
  71. 2) show_license ;;
  72. 3) echo -e "\nGoodbye!"; exit 0 ;;
  73. *) echo "Invalid option. Try again." ;;
  74. esac
  75.  
  76. done
  77.  
  78.  
Advertisement
Add Comment
Please, Sign In to add comment