aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillermo Ramos2021-09-12 21:18:11 +0200
committerGuillermo Ramos2021-09-12 21:18:11 +0200
commit45b60696040d0704f666bdf0b8ace8b09feb1590 (patch)
tree1ce276ddf4c438eae9730c8410b9424d568c3a63
parente2a723f67ad570942cd70dc3434ef3a9718e17b2 (diff)
downloadcli-45b60696040d0704f666bdf0b8ace8b09feb1590.tar.gz
gromo: store gromo seconds per entry
-rwxr-xr-xgromo19
1 files changed, 12 insertions, 7 deletions
diff --git a/gromo b/gromo
index 7e3474a..63cb7c3 100755
--- a/gromo
+++ b/gromo
@@ -88,19 +88,24 @@ cmd_status() {
sum_subtasks() {
file=$1
- awk -F $FS '{ sum += $2 } END { print sum }' "$file"
+ awk -F $FS '{ sum += $3 } END { print sum }' "$file"
}
inc_subtask() {
task=$1
maintask="${fulltask%%.*}"
task_file="$TODAY_DIR/$maintask"
- if [ -f "$task_file" ]; then
- awk -F $FS "\$1 == \"$task\" { \$2 += 1; added=1 } { print \$1 FS \$2 } END { if (!added) { print \"$task\" FS 1 } }" "$task_file" > tmp
- mv tmp "$task_file"
- else
- echo "${task}${FS}1" > "$task_file"
+ if [ ! -f "$task_file" ]; then
+ touch "$task_file"
fi
+
+ awk -F $FS -f - "$task_file" > tmp <<EOF
+BEGIN { OFS = FS }
+\$1 == "$task" && \$2 == "$GROMO_SECONDS" { \$3 += 1; added=1 }
+{ print }
+END { if (!added) { print "$task" FS $GROMO_SECONDS FS 1 } }
+EOF
+ mv tmp "$task_file"
}
pp_seconds() {
@@ -139,7 +144,7 @@ while getopts "$optspec" optchar; do
;;
*)
cmd_help
- exit 0
+ exit -1
;;
esac
done