/
psergee
/
BreakTimer
Обзор
Документация
Войти
/
psergee
/
BreakTimer
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
break_timer.sh
106 строк
3 KB
psergee
Add command line options and improve autostart functionality
04 дек 2025, 01:06
04 дек 2025, 01:06
161fd77
Код
Авторство
О чём код?
#!/bin/bash script_dir=$(realpath $(dirname $0)) script_name=`basename $0` # Default values worktime="50m" breaktime="10m" snoozetime="5m" # Function to display usage information function usage() { echo "Usage: $script_name [OPTIONS] [COMMAND]" echo "" echo "Options:" echo " -w, --work-time TIME Set work time (default: 50m)" echo " -b, --break-time TIME Set break time (default: 10m)" echo " -s, --snooze-time TIME Set snooze time (default: 5m)" echo " -h, --help Show this help message" echo "" echo "Commands:" echo " autostart Create autostart entry for BreakTimer" echo "" echo "Examples:" echo " $script_name -w 30m -b 5m" echo " $script_name --work-time 1h --break-time 15m --snooze-time 10m" } # Create autostart desktop file. function autostart() { absolute_script_path="$script_dir/$script_name" mkdir -p $HOME/.config/autostart desktop_file="$HOME/.config/autostart/breaktimer.desktop" if [ -f "$desktop_file" ]; then echo "Autostart file already exists: $desktop_file" return fi echo "[Desktop Entry] Name=BreakTimer Comment=Application that reminds me to take a break Exec=$absolute_script_path Terminal=false Type=Application Categories=Utility; StartupNotify=false Hidden=false X-GNOME-Autostart-enabled=true" > $HOME/.config/autostart/breaktimer.desktop } # Parse command line arguments while [[ $# -gt 0 ]]; do case $1 in -w|--work-time) worktime="$2" shift 2 ;; -b|--break-time) breaktime="$2" shift 2 ;; -s|--snooze-time) snoozetime="$2" shift 2 ;; -h|--help) usage exit 0 ;; autostart) autostart exit 0 ;; *) echo "Unknown option: $1" usage exit 1 ;; esac done waittime=$worktime while true do sleep $waittime answer=$(zenity --info --text='<span font="26" foreground="#4CAF50">Time for a break!</span>' \ --extra-button "Snooze (${snoozetime})" --extra-button "Restart" --modal \ --title="BreakTimer" --icon="dialog-information" \ ) if [[ $answer == "" ]]; then sleep $breaktime zenity --info --text='<span font="26" foreground="#2196F3">Time to focus.</span>' --modal \ --title="BreakTimer" --icon="dialog-information" waittime=$worktime continue elif [[ $answer == Snooze* ]]; then # Snooze button. waittime=$snoozetime continue else # Restart button. Restarts focus period. waittime=$worktime continue fi done