diff options
Diffstat (limited to 'gromo')
-rwxr-xr-x | gromo | 61 |
1 files changed, 45 insertions, 16 deletions
@@ -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] <task>\tStart task - Options: + Options: -1 Oneshot: stop after first gromo is completed without blocking the screen. + -d <dur> + Set custom gromo duration (format: Ns, Nm, Nh). + + -s <dur> + 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 <dur>[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 <<EOF BEGIN { OFS = FS } -\$1 == "$task" && \$2 == "$GROMO_SECONDS" { \$3 += 1; added=1 } +\$1 == "$task" && \$2 == "$gromo_duration" { \$3 += 1; added=1 } { print } -END { if (!added) { print "$task" FS $GROMO_SECONDS FS 1 } } +END { if (!added) { print "$task" FS $gromo_duration FS 1 } } EOF mv tmp "$task_file" } @@ -136,21 +163,16 @@ pp_seconds() { fi } -optspec="1hsxl" +optspec="1hxld:s:" while getopts "$optspec" optchar; do case "$optchar" in 1) oneshot=1 - shift; ;; h) cmd_help exit 0 ;; - s) - cmd_status - exit 0 - ;; x) cmd_status xmobar exit 0 @@ -159,17 +181,24 @@ while getopts "$optspec" optchar; do cmd_list exit 0 ;; + d) + gromo_duration=$(parse_duration "${OPTARG}") || exit 1 + ;; + s) + stop_duration=$(parse_duration "${OPTARG}") || exit 1 + ;; *) cmd_help - exit -1 + exit 1 ;; esac done +shift $(($OPTIND - 1)) if [ "$#" -eq 1 ]; then fulltask="$1" else - cmd_help + cmd_status exit 0 fi @@ -188,7 +217,7 @@ while true; do echo -ne "\r\033[K[** IN PROGRESS: $fulltask **] " echo "$fulltask" > "$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 |