diff options
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/task/context | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/bin/task/context b/bin/task/context index d1942a5..c8e3f7a 100755 --- a/bin/task/context +++ b/bin/task/context | |||
@@ -37,14 +37,27 @@ _get_seconds() { | |||
37 | echo "${hour:-0}*3600 + ${min:-0}*60 + ${sec:-0}" | bc | xargs printf '%.0f\n' | 37 | echo "${hour:-0}*3600 + ${min:-0}*60 + ${sec:-0}" | bc | xargs printf '%.0f\n' |
38 | } | 38 | } |
39 | 39 | ||
40 | # Get formated string from given seconds | ||
41 | _format_seconds() { | ||
42 | hour=$(( $1 / 3600 )) | ||
43 | min=$(( ($1 % 3600) / 60 )) | ||
44 | sec=$(( $1 % 60 )) | ||
45 | |||
46 | echo ${hour}h${min}m${sec}s | ||
47 | } | ||
48 | |||
40 | _save_spend_time_to_dic() { | 49 | _save_spend_time_to_dic() { |
41 | while read -r ctx sec; do | 50 | while read -r ctx sec; do |
42 | [ -z "$ctx" ] && continue | ||
43 | 51 | ||
52 | [ -z "$ctx" ] && continue | ||
44 | SPEND[$ctx]=$sec | 53 | SPEND[$ctx]=$sec |
45 | done <$LOG_FILE | 54 | done <$LOG_FILE |
46 | } | 55 | } |
47 | 56 | ||
57 | _desktop_notify() { | ||
58 | which notify-send &>/dev/null && notify-send "$context +$1" | ||
59 | } | ||
60 | |||
48 | # Update spend time on current context | 61 | # Update spend time on current context |
49 | _update_spend_time() { | 62 | _update_spend_time() { |
50 | # If current conetxt is not given, exit with 1 | 63 | # If current conetxt is not given, exit with 1 |
@@ -64,12 +77,14 @@ _update_spend_time() { | |||
64 | [ "$SET" = true ] && break | 77 | [ "$SET" = true ] && break |
65 | 78 | ||
66 | sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE | 79 | sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE |
80 | _desktop_notify "$(_format_seconds ${total})" | ||
67 | exit 0 | 81 | exit 0 |
68 | fi | 82 | fi |
69 | # Update Log file | 83 | # Update Log file |
70 | done <"$LOG_FILE" | 84 | done <"$LOG_FILE" |
71 | 85 | ||
72 | echo -e "$context\t${given_seconds}" >>$LOG_FILE | 86 | echo -e "$context\t${given_seconds}" >>$LOG_FILE |
87 | _desktop_notify "$(_format_seconds "${given_seconds}")" | ||
73 | } | 88 | } |
74 | 89 | ||
75 | # Print spend for each context | 90 | # Print spend for each context |