diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2023-04-06 23:12:47 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2023-04-06 23:12:47 +0800 |
commit | 6eb996c031841182eedf6e3dc25a343906ae55a8 (patch) | |
tree | 62d6c23c9bbc26fbe288dc28424ce3821aebbb87 /bin/task/context | |
parent | e78991f3d49aa26675d70b6188cd4a23ef231cc9 (diff) |
Update
Diffstat (limited to 'bin/task/context')
-rwxr-xr-x | bin/task/context | 31 |
1 files changed, 31 insertions, 0 deletions
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 @@ | |||
1 | #! /bin/bash | ||
2 | |||
3 | LOG_FILE=~/log/context && touch $LOG_FILE | ||
4 | context="$(cat ~/.task/context)" | ||
5 | count="$1" | ||
6 | |||
7 | if [ -z "$context" ] || [ "$context" = none ]; then | ||
8 | exit 1 | ||
9 | fi | ||
10 | |||
11 | if [ -n "$1" ]; then | ||
12 | # Update Log file | ||
13 | while read -r ctx sec; do | ||
14 | if [ "$ctx" = "$context" ]; then | ||
15 | summary=$(( "$sec" + "$count" )) | ||
16 | update=true | ||
17 | break | ||
18 | fi | ||
19 | done <$LOG_FILE | ||
20 | if [ "$update" = true ]; then | ||
21 | sed -i -E "s/^$context.*/$context\t$summary" $LOG_FILE | ||
22 | else | ||
23 | echo -e "$context\t$count" >>$LOG_FILE | ||
24 | fi | ||
25 | else | ||
26 | # Print times for each context | ||
27 | while read -r ctx sec; do | ||
28 | echo -ne "$ctx\t" | ||
29 | date -u -d @"$sec" +%H:%M | ||
30 | done <$LOG_FILE | ||
31 | fi | ||