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 +++++++++++++++++++++++++++++++ bin/task/context_spend_time.sh | 31 ------------------------------- 2 files changed, 31 insertions(+), 31 deletions(-) create mode 100755 bin/task/context delete mode 100755 bin/task/context_spend_time.sh (limited to 'bin/task') 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 diff --git a/bin/task/context_spend_time.sh b/bin/task/context_spend_time.sh deleted file mode 100755 index 8da42c7..0000000 --- a/bin/task/context_spend_time.sh +++ /dev/null @@ -1,31 +0,0 @@ -#! /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:%S - done <$LOG_FILE -fi -- cgit v1.2.3-70-g09d2