diff options
Diffstat (limited to 'bin/task')
-rwxr-xr-x | bin/task/context | 36 |
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 | |||
14 | PLAN_FILE=~/log/plan.context.md | 14 | PLAN_FILE=~/log/plan.context.md |
15 | PROC=$$ | 15 | PROC=$$ |
16 | 16 | ||
17 | context="$(cat ~/.task/context)" | 17 | if [[ "$1" =~ ^e ]]; then |
18 | [[ "$*" =~ '-s' ]] && SET=true && shift | 18 | $EDITOR $LOG_FILE |
19 | [[ "$1" =~ ^[a-zA-Z] ]] && { | 19 | exit 0 |
20 | elif [[ "$1" =~ ^[a-zA-Z] ]]; then | ||
20 | echo "$1" > ~/.task/context | 21 | echo "$1" > ~/.task/context |
21 | exit 0 | 22 | exit 0 |
22 | } | 23 | fi |
24 | |||
25 | context="$(cat ~/.task/context)" | ||
23 | time="$1" | 26 | time="$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 |