From 6eb996c031841182eedf6e3dc25a343906ae55a8 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 6 Apr 2023 23:12:47 +0800 Subject: Update --- bin/task/context | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100755 bin/task/context (limited to 'bin/task/context') diff --git a/bin/task/context b/bin/task/context new file mode 100755 index 0000000..d81573b --- /dev/null +++ b/bin/task/context @@ -0,0 +1,31 @@ +#! /bin/bash + +LOG_FILE=~/log/context && touch $LOG_FILE +context="$(cat ~/.task/context)" +count="$1" + +if [ -z "$context" ] || [ "$context" = none ]; then + exit 1 +fi + +if [ -n "$1" ]; then + # Update Log file + while read -r ctx sec; do + if [ "$ctx" = "$context" ]; then + summary=$(( "$sec" + "$count" )) + update=true + break + fi + done <$LOG_FILE + if [ "$update" = true ]; then + sed -i -E "s/^$context.*/$context\t$summary" $LOG_FILE + else + echo -e "$context\t$count" >>$LOG_FILE + fi +else + # Print times for each context + while read -r ctx sec; do + echo -ne "$ctx\t" + date -u -d @"$sec" +%H:%M + done <$LOG_FILE +fi -- cgit v1.2.3-70-g09d2