From cb2568693f1caf398c4425852e8e496f1fc4a7ba Mon Sep 17 00:00:00 2001 From: Guillermo Ramos Date: Mon, 13 Sep 2021 09:58:37 +0200 Subject: gromo: options for custom durations --- gromo | 61 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/gromo b/gromo index cadd495..d15dccd 100755 --- a/gromo +++ b/gromo @@ -17,8 +17,6 @@ shopt -s nullglob DEFAULT_DING=https://gramos.me/ding.opus -GROMO_SECONDS=$((60 * 20)) -STOP_SECONDS=20 DATA_DIR=${XDG_DATA_HOME:-$HOME/.local/share}/gromo CACHE_DIR=${XDG_CACHE_HOME:-$HOME/.cache}/gromo @@ -29,21 +27,31 @@ STATE_FILE=${XDG_STATE_HOME:-$HOME/.local/state}/gromo FS=: +gromo_duration=$((60 * 20)) +stop_duration=20 + cmd_help() { cmd=$(basename "$0") echo -e "Usage: $cmd -h \tShow this help - $cmd -s \tShow status $cmd -x \tShow status formatted for xmobar $cmd -l \tList past gromos + + $cmd \tShow status $cmd [options] \tStart task - Options: + Options: -1 Oneshot: stop after first gromo is completed without blocking the screen. + -d + Set custom gromo duration (format: Ns, Nm, Nh). + + -s + Set custom stop duration (format: Ns, Nm, Nh). Ignored if combined with -1. + Tasks can be divided in subtasks by using dots (.), e.g., 'gromo work.retro'. Only the first level is taken into account for organization purposes: the top-level task is considered the 'main task' and a file is created after it to account for its subtasks. @@ -103,6 +111,25 @@ EOF fi } +parse_duration() { + duration=$1 + case ${duration:0,-1} in + s) + echo ${duration%s} + ;; + m) + echo $((${duration%m} * 60)) + ;; + h) + echo $((${duration%h} * 60 * 60)) + ;; + *) + echo "ERROR: Invalid duration format. Must be [smh]." >&2 + return 1 + ;; + esac +} + sum_subtasks() { file=$1 awk -F $FS '{ sum += $3 } END { print sum }' "$file" @@ -118,9 +145,9 @@ inc_subtask() { awk -F $FS -f - "$task_file" > tmp < "$STATE_FILE" - sleep $GROMO_SECONDS + sleep $gromo_duration echo idle > "$STATE_FILE" inc_subtask "$fulltask" @@ -198,6 +227,6 @@ while true; do exit 0 fi - (sleep $STOP_SECONDS && mpv --no-terminal "$DING_FILE") & + (sleep $stop_duration && mpv --no-terminal "$DING_FILE") & slock || exit done -- cgit v1.2.3