Skip to content

Instantly share code, notes, and snippets.

@MasWag
Created February 7, 2023 06:47
Show Gist options
  • Save MasWag/711b61ff7332bf4a6eab5151b2eeb06e to your computer and use it in GitHub Desktop.
Save MasWag/711b61ff7332bf4a6eab5151b2eeb06e to your computer and use it in GitHub Desktop.
#!/bin/bash -u
function finish {
hours=$((elapsed / 3600))
minutes=$(((elapsed % 3600) / 60))
seconds=$((elapsed % 60))
if [ $hours -gt 0 ]; then
time_string="$hours 時間 $minutes 分 $seconds 秒"
elif [ $minutes -gt 0 ]; then
time_string="$minutes 分 $seconds 秒"
else
time_string="$seconds 秒"
fi
say -v Kyoko "$time_string です"
}
trap finish EXIT
start=$(date +%s)
echo "Press [CTRL+C] to stop.."
while true; do
clear
current=$(date +%s)
elapsed=$((current - start))
hours=$((elapsed / 3600))
minutes=$(((elapsed % 3600) / 60))
seconds=$((elapsed % 60))
printf "%02d:%02d:%02d\n" $hours $minutes $seconds
if [ $minutes -gt 0 ] && [ $((minutes % 5)) -eq 0 ] && [ $seconds -lt 2 ]; then
say -v Kyoko "$minutes 分です"
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment