aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/task/context_spend_time.sh
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-04-06 21:44:47 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-04-06 21:44:47 +0800
commit71dce3a13572fdae0ce5f7b1169c69ea9610d800 (patch)
tree5f04b413f10407b8ea6a834b237f6775d19a77f0 /bin/task/context_spend_time.sh
parentff3dfc91aebd454323a25baf6ffd8c9145747564 (diff)
Add feature for time of current context
Diffstat (limited to 'bin/task/context_spend_time.sh')
-rwxr-xr-xbin/task/context_spend_time.sh31
1 files changed, 31 insertions, 0 deletions
diff --git a/bin/task/context_spend_time.sh b/bin/task/context_spend_time.sh
new file mode 100755
index 0000000..cbadc47
--- /dev/null
+++ b/bin/task/context_spend_time.sh
@@ -0,0 +1,31 @@
1#! /bin/bash
2
3LOG_FILE=~/log/context
4context="$(cat ~/.task/context)"
5count="$1"
6
7if [ -z "$context" ] || [ "$context" = none ]; then
8 exit 1
9fi
10
11if [ -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$summary" >>$LOG_FILE
24 fi
25else
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:%S
30 done <$LOG_FILE
31fi