From c7474c83392dba4b1d385ca45ff968a2b922b399 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 11 Apr 2023 23:17:36 +0800 Subject: Update --- bin/task/context | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'bin/task/context') 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() { echo "${hour:-0}*3600 + ${min:-0}*60 + ${sec:-0}" | bc | xargs printf '%.0f\n' } +# Get formated string from given seconds +_format_seconds() { + hour=$(( $1 / 3600 )) + min=$(( ($1 % 3600) / 60 )) + sec=$(( $1 % 60 )) + + echo ${hour}h${min}m${sec}s +} + _save_spend_time_to_dic() { while read -r ctx sec; do - [ -z "$ctx" ] && continue + [ -z "$ctx" ] && continue SPEND[$ctx]=$sec done <$LOG_FILE } +_desktop_notify() { + which notify-send &>/dev/null && notify-send "$context +$1" +} + # Update spend time on current context _update_spend_time() { # If current conetxt is not given, exit with 1 @@ -64,12 +77,14 @@ _update_spend_time() { [ "$SET" = true ] && break sed -i -E "s/^${context}.*/${context}\t${total}/" $LOG_FILE + _desktop_notify "$(_format_seconds ${total})" exit 0 fi # Update Log file done <"$LOG_FILE" echo -e "$context\t${given_seconds}" >>$LOG_FILE + _desktop_notify "$(_format_seconds "${given_seconds}")" } # Print spend for each context -- cgit v1.2.3-70-g09d2