aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/task/context
diff options
context:
space:
mode:
Diffstat (limited to 'bin/task/context')
-rwxr-xr-xbin/task/context36
1 files changed, 11 insertions, 25 deletions
diff --git a/bin/task/context b/bin/task/context
index c67b4de..95d17c1 100755
--- a/bin/task/context
+++ b/bin/task/context
@@ -14,12 +14,15 @@ LOG_FILE=~/.context && touch $LOG_FILE
14PLAN_FILE=~/log/plan.context.md 14PLAN_FILE=~/log/plan.context.md
15PROC=$$ 15PROC=$$
16 16
17context="$(cat ~/.task/context)" 17if [[ "$1" =~ ^e ]]; then
18[[ "$*" =~ '-s' ]] && SET=true && shift 18 $EDITOR $LOG_FILE
19[[ "$1" =~ ^[a-zA-Z] ]] && { 19 exit 0
20elif [[ "$1" =~ ^[a-zA-Z] ]]; then
20 echo "$1" > ~/.task/context 21 echo "$1" > ~/.task/context
21 exit 0 22 exit 0
22} 23fi
24
25context="$(cat ~/.task/context)"
23time="$1" 26time="$1"
24 27
25# The unit of time display. For example: 28# The unit of time display. For example:
@@ -54,11 +57,9 @@ _format_seconds() {
54} 57}
55 58
56_save_spend_time_to_dic() { 59_save_spend_time_to_dic() {
57 while read -r ctx sec; do 60 while read -r date time ctx sec; do
58 61 SPEND[$ctx]=$(( SPEND[$ctx] + $sec ))
59 [ -z "$ctx" ] && continue 62 done < <(sed -n "/^$(date +%Y%m%d)/p" $LOG_FILE)
60 SPEND[$ctx]=$sec
61 done <$LOG_FILE
62} 63}
63 64
64_desktop_notify() { 65_desktop_notify() {
@@ -75,22 +76,7 @@ _update_spend_time() {
75 given_seconds="$(_get_seconds "$time")" 76 given_seconds="$(_get_seconds "$time")"
76 _desktop_notify "$(_format_seconds "${given_seconds}")" 77 _desktop_notify "$(_format_seconds "${given_seconds}")"
77 78
78 # Get total time of given time and current context time 79 echo -e "$(date +'%Y%m%d %H:%m:%S')\t$context\t${given_seconds}" >>$LOG_FILE
79 while read -r ctx sec; do
80 if [ "$ctx" = "$context" ]; then
81 total=$(( "$sec" + "$given_seconds" ))
82 if [ "$SET" = true ]; then
83 sed -i -E "/^${context}.*/d" $LOG_FILE
84 break
85 else
86 sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE
87 exit 0
88 fi
89 fi
90 # Update Log file
91 done <"$LOG_FILE"
92
93 echo -e "$context\t${given_seconds}" >>$LOG_FILE
94} 80}
95 81
96# Print spend for each context 82# Print spend for each context