Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # USE: ./stopwatch.scr and select an option.
- echo
- TZ=GMT date +"%d:%m:%Y - %H:%M:%S:$(date +%3N) - %s"
- echo
- # Menu Function
- show_menu() {
- echo "Select an option:"
- echo "1) Start Chrono for 'Human Biology works and execises (Published on diaspora.psyco.fr/tags/human_biology')"
- echo "2) View License"
- echo "3) Exit"
- }
- # License Function
- show_license() {
- echo -e "\n19:02:2025 (1739962099) Copyright (c) Peregrino Alemán Armas"
- echo "Permission is hereby granted, free of charge, to any person obtaining"
- echo "a copy of this software and associated documentation files (the"
- echo "\"Software\"), to deal in the Software without restriction, including"
- echo "without limitation the rights to use, copy, modify, merge, publish,"
- echo "distribute, sublicense, and/or sell copies of the Software, and to"
- echo "permit persons to whom the Software is furnished to do so, subject to"
- echo "the following conditions:"
- echo
- echo "The above copyright notice and this permission notice shall be"
- echo "included in all copies or substantial portions of the Software."
- echo
- echo "THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,"
- echo "EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF"
- echo "MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND"
- echo "NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE"
- echo "LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION"
- echo "OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION"
- echo "WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
- echo -e "\n"
- }
- # Stopwatch Function
- start_stopwatch() {
- echo "Chrono 'Race' started. Press '1' to stop."
- start_time=$(date +%s%3N) # Start time in milliseconds
- while true; do
- current_time=$(date +%s%3N) # Get current time in milliseconds
- elapsed=$((current_time - start_time)) # Calculate elapsed time
- min=$((elapsed / 60000)) # Convert to minutes
- sec=$(( (elapsed / 1000) % 60 )) # Convert to seconds
- ms=$((elapsed % 1000)) # Get milliseconds
- printf "\r%02d:%02d:%03d" "$min" "$sec" "$ms" # Print formatted time
- # Check for keypress to stop stopwatch
- read -t 0.01 -n 1 key
- if [[ "$key" == "1" ]]; then
- echo -e "\nStopped at: $min:$sec:$ms"
- return
- fi
- done
- }
- # Main Menu Loop
- while true; do
- show_menu
- echo ''
- read -p " Enter choice: " choice
- case $choice in
- 1) start_stopwatch ;;
- 2) show_license ;;
- 3) echo -e "\nGoodbye!"; exit 0 ;;
- *) echo "Invalid option. Try again." ;;
- esac
- done
Advertisement
Add Comment
Please, Sign In to add comment