2015-10-15 09:51:47 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
TIME=0
|
|
|
|
# Work on the task (default: 25 min)
|
2015-10-18 12:41:38 +02:00
|
|
|
WORK_TIME=25
|
2015-10-18 12:59:09 +02:00
|
|
|
SHORT_BREAK_TIME=5
|
2015-10-18 13:05:39 +02:00
|
|
|
# Every 4 pomodori
|
2015-10-18 12:59:09 +02:00
|
|
|
LONG_BREAK_TIME=20
|
2015-10-18 02:11:00 +02:00
|
|
|
|
|
|
|
# Log informations
|
|
|
|
LOG_DIR="${HOME}/.pomodoro"
|
2015-10-18 02:54:44 +02:00
|
|
|
LOG_TASK_NAME=$(date +"week-%V-%Y.txt")
|
|
|
|
LOG_TASK_PATH="${LOG_DIR}/${LOG_TASK_NAME}"
|
2015-10-18 02:11:00 +02:00
|
|
|
|
2015-10-15 09:51:47 +02:00
|
|
|
# Task information (name, path, …)
|
|
|
|
TASK_NAME="${1}"
|
2015-10-18 02:11:00 +02:00
|
|
|
TASK_PATH="${LOG_DIR}/current.task"
|
|
|
|
|
2015-10-18 12:59:09 +02:00
|
|
|
initialize() {
|
|
|
|
# Create the log dir
|
|
|
|
if [ ! -d "${LOG_DIR}" ]; then
|
|
|
|
mkdir -p -- "${LOG_DIR}"
|
|
|
|
fi
|
2015-10-15 09:51:47 +02:00
|
|
|
|
2015-10-18 12:59:09 +02:00
|
|
|
# Create the task file
|
|
|
|
if [ ! -f "${TASK_PATH}" ]; then
|
|
|
|
touch "${TASK_PATH}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Create the task log file
|
|
|
|
if [ ! -f "${LOG_TASK_PATH}" ]; then
|
|
|
|
touch "${LOG_TASK_PATH}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# ------------- START -------------
|
|
|
|
|
|
|
|
initialize
|
2015-10-18 02:54:44 +02:00
|
|
|
|
|
|
|
# Start working
|
|
|
|
startedTime=$(date +"%H:%M")
|
|
|
|
|
2015-10-18 12:41:38 +02:00
|
|
|
printf '%b' "${TASK_NAME}\n${TIME}" > "${TASK_PATH}"
|
|
|
|
|
2015-10-15 09:51:47 +02:00
|
|
|
# Tiny timer
|
2015-10-18 12:41:38 +02:00
|
|
|
while [ "${TIME}" != "${WORK_TIME}" ]; do
|
|
|
|
sleep 60
|
2015-10-15 09:51:47 +02:00
|
|
|
TIME=$((TIME+1))
|
2015-10-18 12:41:38 +02:00
|
|
|
printf '%b' "${TASK_NAME}\n${TIME}" > "${TASK_PATH}"
|
2015-10-15 09:51:47 +02:00
|
|
|
done
|
|
|
|
|
2015-10-18 02:54:44 +02:00
|
|
|
# Write logs
|
2015-10-18 13:05:39 +02:00
|
|
|
printf '%b' "$(date +"%A (%F) $startedTime → %H:%M") $TASK_NAME\n" >> "${LOG_TASK_PATH}"
|
2015-10-18 02:54:44 +02:00
|
|
|
|
2015-10-18 12:41:38 +02:00
|
|
|
# Start break
|
2015-10-18 13:05:39 +02:00
|
|
|
if [ `expr ${num} % 4` -eq 0 ]; then
|
|
|
|
BREAK_TIME=${LONG_BREAK_TIME}
|
|
|
|
BREAK_MSG="Relax"
|
|
|
|
else
|
|
|
|
BREAK_TIME=${SHORT_BREAK_TIME}
|
|
|
|
BREAK_MSG="Pause"
|
|
|
|
fi
|
|
|
|
|
2015-10-18 12:59:09 +02:00
|
|
|
BREAK_TIME=${SHORT_BREAK_TIME}
|
2015-10-18 13:05:39 +02:00
|
|
|
printf '%b' "${BREAK_MSG}\n${BREAK_TIME}" > "${TASK_PATH}"
|
2015-10-18 12:41:38 +02:00
|
|
|
|
|
|
|
while [ "${BREAK_TIME}" > 0 ]; do
|
|
|
|
sleep 60
|
|
|
|
BREAK_TIME=$((BREAK_TIME-1))
|
2015-10-18 13:05:39 +02:00
|
|
|
printf '%b' "${BREAK_MSG}\n${BREAK_TIME}" > "${TASK_PATH}"
|
2015-10-18 12:41:38 +02:00
|
|
|
done
|
|
|
|
|
2015-10-15 09:51:47 +02:00
|
|
|
exit 0
|