diff options
author | Guillermo Ramos | 2021-09-12 21:44:42 +0200 |
---|---|---|
committer | Guillermo Ramos | 2021-09-12 21:44:42 +0200 |
commit | dc77ba26d1a749de93a550aaefc9b3c30bc736d0 (patch) | |
tree | 1687965438af92d6d3f63fccd8a1458b37d794b8 | |
parent | 45b60696040d0704f666bdf0b8ace8b09feb1590 (diff) | |
download | cli-dc77ba26d1a749de93a550aaefc9b3c30bc736d0.tar.gz |
gromo: -s overhaul
-rwxr-xr-x | gromo | 41 |
1 files changed, 29 insertions, 12 deletions
@@ -35,8 +35,8 @@ cmd_help() { 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 -x \tReturn state formatted for display in xmobar $cmd [options] <task>\tStart task Options: @@ -57,12 +57,12 @@ cmd_list() { cmd_status() { format=$1 - state=idle - [ -f "$STATE_FILE" ] && state=$(cat "$STATE_FILE") + status=idle + [ -f "$STATE_FILE" ] && status=$(cat "$STATE_FILE") if [ "$format" = "xmobar" ]; then color=red - [ "$state" = "idle" ] && color=green + [ "$status" = "idle" ] && color=green if [ -d "$TODAY_DIR" ]; then today="" @@ -73,14 +73,31 @@ cmd_status() { [ -n "$today" ] && today=" (${today%, })" fi - echo "<fc=$color>$state</fc>$today" + echo "<fc=$color>$status</fc>$today" else - echo -e "state: $state\n" + echo -e "status: $status\n" if [ -d "$TODAY_DIR" ]; then # needs nullglob for task_file in "$TODAY_DIR"/*; do - sort < "$task_file" + out=$( + awk -F $FS -f - "$task_file" <<EOF +{ tasks[\$1][\$2] = \$3 } +END { + for (task in tasks) { + for (dur in tasks[task]) { + gromos += tasks[task][dur]; + time += dur * tasks[task][dur] + }; + print task ":" time ":" gromos + } +} +EOF + ) + + while IFS=$FS read -r task dur gromos; do + echo -e "$task\n\t$gromos gromos, $(pp_seconds $dur)" + done <<<"$out" done fi fi @@ -119,7 +136,7 @@ pp_seconds() { fi } -optspec="1hslx" +optspec="1hsxl" while getopts "$optspec" optchar; do case "$optchar" in 1) @@ -134,14 +151,14 @@ while getopts "$optspec" optchar; do cmd_status exit 0 ;; - l) - cmd_list - exit 0 - ;; x) cmd_status xmobar exit 0 ;; + l) + cmd_list + exit 0 + ;; *) cmd_help exit -1 |