diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2023-04-12 13:18:22 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2023-04-12 13:18:22 +0800 |
commit | 4727b9029c47811e2ae94c46abca4c80a3ab77a1 (patch) | |
tree | 40d5f144380e06afd944563a78c276a7ccc27330 /bin/task/context | |
parent | 73e2aa4cee08900882d77cb94a74c338aa9740f2 (diff) |
Add trap for remote sync
Diffstat (limited to 'bin/task/context')
-rwxr-xr-x | bin/task/context | 18 |
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 | # | ||
10 | trap 'exit 1' SIGUSR1 | ||
11 | trap 'which rsync_retry.sh &>/dev/null && setsid rsync_retry.sh $LOG_FILE &>/dev/null &' EXIT | ||
9 | 12 | ||
10 | LOG_FILE=~/.context && touch $LOG_FILE | 13 | LOG_FILE=~/.context && touch $LOG_FILE |
11 | PLAN_FILE=~/log/plan.context.md | 14 | PLAN_FILE=~/log/plan.context.md |
12 | PROC=$$ | 15 | PROC=$$ |
13 | trap 'exit 1' SIGUSR1 | ||
14 | trap 'rsync_retry $0' EXIT | ||
15 | 16 | ||
16 | context="$(cat ~/.task/context)" | 17 | context="$(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" |