aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-04-12 13:18:22 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-04-12 13:18:22 +0800
commit4727b9029c47811e2ae94c46abca4c80a3ab77a1 (patch)
tree40d5f144380e06afd944563a78c276a7ccc27330
parent73e2aa4cee08900882d77cb94a74c338aa9740f2 (diff)
Add trap for remote sync
-rwxr-xr-xbin/task/context18
1 files changed, 11 insertions, 7 deletions
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 @@
6# context (Check total time of each context) 6# context (Check total time of each context)
7# 7#
8# TODO support minus time 8# TODO support minus time
9#
10trap 'exit 1' SIGUSR1
11trap 'which rsync_retry.sh &>/dev/null && setsid rsync_retry.sh $LOG_FILE &>/dev/null &' EXIT
9 12
10LOG_FILE=~/.context && touch $LOG_FILE 13LOG_FILE=~/.context && touch $LOG_FILE
11PLAN_FILE=~/log/plan.context.md 14PLAN_FILE=~/log/plan.context.md
12PROC=$$ 15PROC=$$
13trap 'exit 1' SIGUSR1
14trap 'rsync_retry $0' EXIT
15 16
16context="$(cat ~/.task/context)" 17context="$(cat ~/.task/context)"
17[[ "$*" =~ '-s' ]] && SET=true && shift 18[[ "$*" =~ '-s' ]] && SET=true && shift
@@ -75,11 +76,14 @@ _update_spend_time() {
75 while read -r ctx sec; do 76 while read -r ctx sec; do
76 if [ "$ctx" = "$context" ]; then 77 if [ "$ctx" = "$context" ]; then
77 total=$(( "$sec" + "$given_seconds" )) 78 total=$(( "$sec" + "$given_seconds" ))
78 [ "$SET" = true ] && break 79 if [ "$SET" = true ]; then
79 80 sed -i -E "/^${context}.*/d" $LOG_FILE
80 sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE 81 break
81 _desktop_notify "$(_format_seconds ${total})" 82 else
82 exit 0 83 sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE
84 _desktop_notify "$(_format_seconds ${total})"
85 exit 0
86 fi
83 fi 87 fi
84 # Update Log file 88 # Update Log file
85 done <"$LOG_FILE" 89 done <"$LOG_FILE"