From 4727b9029c47811e2ae94c46abca4c80a3ab77a1 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Wed, 12 Apr 2023 13:18:22 +0800 Subject: Add trap for remote sync --- bin/task/context | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'bin/task/context') diff --git a/bin/task/context b/bin/task/context index fd10baf..3e69db4 100755 --- a/bin/task/context +++ b/bin/task/context @@ -6,12 +6,13 @@ # context (Check total time of each context) # # TODO support minus time +# +trap 'exit 1' SIGUSR1 +trap 'which rsync_retry.sh &>/dev/null && setsid rsync_retry.sh $LOG_FILE &>/dev/null &' EXIT LOG_FILE=~/.context && touch $LOG_FILE PLAN_FILE=~/log/plan.context.md PROC=$$ -trap 'exit 1' SIGUSR1 -trap 'rsync_retry $0' EXIT context="$(cat ~/.task/context)" [[ "$*" =~ '-s' ]] && SET=true && shift @@ -75,11 +76,14 @@ _update_spend_time() { while read -r ctx sec; do if [ "$ctx" = "$context" ]; then total=$(( "$sec" + "$given_seconds" )) - [ "$SET" = true ] && break - - sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE - _desktop_notify "$(_format_seconds ${total})" - exit 0 + if [ "$SET" = true ]; then + sed -i -E "/^${context}.*/d" $LOG_FILE + break + else + sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE + _desktop_notify "$(_format_seconds ${total})" + exit 0 + fi fi # Update Log file done <"$LOG_FILE" -- cgit v1.2.3-70-g09d2