From 6eb996c031841182eedf6e3dc25a343906ae55a8 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Thu, 6 Apr 2023 23:12:47 +0800 Subject: Update --- X11/show_timer.sh | 6 ++++-- bin/task/context | 31 +++++++++++++++++++++++++++++++ bin/task/context_spend_time.sh | 31 ------------------------------- 3 files changed, 35 insertions(+), 33 deletions(-) create mode 100755 bin/task/context delete mode 100755 bin/task/context_spend_time.sh diff --git a/X11/show_timer.sh b/X11/show_timer.sh index dfe3dd2..dd6d877 100755 --- a/X11/show_timer.sh +++ b/X11/show_timer.sh @@ -3,11 +3,13 @@ origin="$(xdotool getactivewindow)" export origin -# If timer is set, focus to it +# If timer is set, focus to it and exit xdotool search --name "TIMER" windowactivate && exit 0 # Add new window for a timer -# Use SIGINT +# Use SIGINT to toggle each mode +# Use xdotool to reactivate original window user focus +# After timer is closed or finished, append time into context file alacritty --title TIMER --hold \ -o "window.dimensions.columns=8" \ -o "window.dimensions.lines=1" \ diff --git a/bin/task/context b/bin/task/context new file mode 100755 index 0000000..d81573b --- /dev/null +++ b/bin/task/context @@ -0,0 +1,31 @@ +#! /bin/bash + +LOG_FILE=~/log/context && touch $LOG_FILE +context="$(cat ~/.task/context)" +count="$1" + +if [ -z "$context" ] || [ "$context" = none ]; then + exit 1 +fi + +if [ -n "$1" ]; then + # Update Log file + while read -r ctx sec; do + if [ "$ctx" = "$context" ]; then + summary=$(( "$sec" + "$count" )) + update=true + break + fi + done <$LOG_FILE + if [ "$update" = true ]; then + sed -i -E "s/^$context.*/$context\t$summary" $LOG_FILE + else + echo -e "$context\t$count" >>$LOG_FILE + fi +else + # Print times for each context + while read -r ctx sec; do + echo -ne "$ctx\t" + date -u -d @"$sec" +%H:%M + done <$LOG_FILE +fi diff --git a/bin/task/context_spend_time.sh b/bin/task/context_spend_time.sh deleted file mode 100755 index 8da42c7..0000000 --- a/bin/task/context_spend_time.sh +++ /dev/null @@ -1,31 +0,0 @@ -#! /bin/bash - -LOG_FILE=~/log/context && touch $LOG_FILE -context="$(cat ~/.task/context)" -count="$1" - -if [ -z "$context" ] || [ "$context" = none ]; then - exit 1 -fi - -if [ -n "$1" ]; then - # Update Log file - while read -r ctx sec; do - if [ "$ctx" = "$context" ]; then - summary=$(( "$sec" + "$count" )) - update=true - break - fi - done <$LOG_FILE - if [ "$update" = true ]; then - sed -i -E "s/^$context.*/$context\t$summary" $LOG_FILE - else - echo -e "$context\t$count" >>$LOG_FILE - fi -else - # Print times for each context - while read -r ctx sec; do - echo -ne "$ctx\t" - date -u -d @"$sec" +%H:%M:%S - done <$LOG_FILE -fi -- cgit v1.2.3-70-g09d2