diff options
author | Hsieh Chin Fan <pham@topo.tw> | 2023-04-20 10:49:03 +0800 |
---|---|---|
committer | Hsieh Chin Fan <pham@topo.tw> | 2023-04-20 10:49:03 +0800 |
commit | 2c14bcea4c65c762c4d969bc22485facf1419045 (patch) | |
tree | e21347785d555b7e3a7d1e2ce3fd864bf001957e | |
parent | d5e4f287d6acfe6f026f222e89ef6e1c28bb9db0 (diff) |
Update
-rwxr-xr-x | bin/task/context | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/bin/task/context b/bin/task/context index 358c548..fcba0fb 100755 --- a/bin/task/context +++ b/bin/task/context | |||
@@ -56,10 +56,13 @@ _get_seconds() { | |||
56 | # Get formated string from given seconds | 56 | # Get formated string from given seconds |
57 | _format_seconds() { | 57 | _format_seconds() { |
58 | hour=$(( $1 / 3600 )) | 58 | hour=$(( $1 / 3600 )) |
59 | [ "$hour" = 0 ] && unset hour | ||
59 | min=$(( ($1 % 3600) / 60 )) | 60 | min=$(( ($1 % 3600) / 60 )) |
61 | [ "$min" = 0 ] && unset min | ||
60 | sec=$(( $1 % 60 )) | 62 | sec=$(( $1 % 60 )) |
63 | [ "$sec" = 0 ] && unset sec | ||
61 | 64 | ||
62 | echo ${hour}h${min}m${sec}s | 65 | echo ${hour:+${hour}h}${min:+${min}m}${sec:+${sec}s} |
63 | } | 66 | } |
64 | 67 | ||
65 | _save_spend_time_to_dic() { | 68 | _save_spend_time_to_dic() { |
@@ -70,7 +73,7 @@ _save_spend_time_to_dic() { | |||
70 | 73 | ||
71 | _desktop_notify() { | 74 | _desktop_notify() { |
72 | which notify-send &>/dev/null || return 1 | 75 | which notify-send &>/dev/null || return 1 |
73 | if [[ "$1" =~ ^[+-] ]]; then | 76 | if [[ "$1" =~ ^- ]]; then |
74 | local time="$1" | 77 | local time="$1" |
75 | else | 78 | else |
76 | local time=+"$1" | 79 | local time=+"$1" |
@@ -86,7 +89,7 @@ _update_spend_time() { | |||
86 | fi | 89 | fi |
87 | 90 | ||
88 | given_seconds="$(_get_seconds "$time")" | 91 | given_seconds="$(_get_seconds "$time")" |
89 | _desktop_notify "$time" | 92 | _desktop_notify "$(_format_seconds "$given_seconds")" |
90 | 93 | ||
91 | echo -e "$(date +'%Y%m%d %H:%M:%S')\t$context\t${given_seconds}" >>$LOG_FILE | 94 | echo -e "$(date +'%Y%m%d %H:%M:%S')\t$context\t${given_seconds}" >>$LOG_FILE |
92 | } | 95 | } |