diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-04-06 21:44:47 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-04-06 21:44:47 +0800 |
| commit | 71dce3a13572fdae0ce5f7b1169c69ea9610d800 (patch) | |
| tree | 5f04b413f10407b8ea6a834b237f6775d19a77f0 | |
| parent | ff3dfc91aebd454323a25baf6ffd8c9145747564 (diff) | |
Add feature for time of current context
| -rwxr-xr-x | X11/show_timer.sh | 8 | ||||
| -rwxr-xr-x | bin/task/context_spend_time.sh | 31 | ||||
| -rwxr-xr-x | bin/unix/timer.sh | 9 |
3 files changed, 42 insertions, 6 deletions
diff --git a/X11/show_timer.sh b/X11/show_timer.sh index 6ff405a..4fbb5e5 100755 --- a/X11/show_timer.sh +++ b/X11/show_timer.sh | |||
| @@ -1,6 +1,7 @@ | |||
| 1 | #! /bin/sh | 1 | #! /bin/sh |
| 2 | 2 | ||
| 3 | export origin=`xdotool getactivewindow`; \ | 3 | origin="$(xdotool getactivewindow)" |
| 4 | export origin | ||
| 4 | 5 | ||
| 5 | # If timer is set, focus to it | 6 | # If timer is set, focus to it |
| 6 | xdotool search --name "TIMER" windowactivate && exit 0 | 7 | xdotool search --name "TIMER" windowactivate && exit 0 |
| @@ -14,4 +15,7 @@ alacritty --title TIMER --hold \ | |||
| 14 | -o "window.position.y=0" \ | 15 | -o "window.position.y=0" \ |
| 15 | -o "window.opacity=0.6" \ | 16 | -o "window.opacity=0.6" \ |
| 16 | -o "font.size=40" \ | 17 | -o "font.size=40" \ |
| 17 | -e sh -c '~/helper/bin/unix/timer.sh SIGINT "xdotool windowactivate $origin"' | 18 | -e "$HOME"/helper/bin/unix/timer.sh \ |
| 19 | SIGINT \ | ||
| 20 | "xdotool windowactivate $origin" \ | ||
| 21 | 'echo $count | ~/helper/bin/task/context_spend_time.sh' | ||
diff --git a/bin/task/context_spend_time.sh b/bin/task/context_spend_time.sh new file mode 100755 index 0000000..cbadc47 --- /dev/null +++ b/bin/task/context_spend_time.sh | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | LOG_FILE=~/log/context | ||
| 4 | context="$(cat ~/.task/context)" | ||
| 5 | count="$1" | ||
| 6 | |||
| 7 | if [ -z "$context" ] || [ "$context" = none ]; then | ||
| 8 | exit 1 | ||
| 9 | fi | ||
| 10 | |||
| 11 | if [ -n "$1" ]; then | ||
| 12 | # Update Log file | ||
| 13 | while read -r ctx sec; do | ||
| 14 | if [ "$ctx" = "$context" ]; then | ||
| 15 | summary=$(( "$sec" + "$count" )) | ||
| 16 | update=true | ||
| 17 | break | ||
| 18 | fi | ||
| 19 | done <$LOG_FILE | ||
| 20 | if [ "$update" = true ]; then | ||
| 21 | sed -i -E "s/^$context.*/$context\t$summary" $LOG_FILE | ||
| 22 | else | ||
| 23 | echo -e "$context\t$summary" >>$LOG_FILE | ||
| 24 | fi | ||
| 25 | else | ||
| 26 | # Print times for each context | ||
| 27 | while read -r ctx sec; do | ||
| 28 | echo -ne "$ctx\t" | ||
| 29 | date -u -d @"$sec" +%H:%M:%S | ||
| 30 | done <$LOG_FILE | ||
| 31 | fi | ||
diff --git a/bin/unix/timer.sh b/bin/unix/timer.sh index 152d828..b4f48c5 100755 --- a/bin/unix/timer.sh +++ b/bin/unix/timer.sh | |||
| @@ -5,7 +5,8 @@ exec 3>&1 | |||
| 5 | exec 1>/dev/tty | 5 | exec 1>/dev/tty |
| 6 | 6 | ||
| 7 | SIGNAL=${1:-SIGTERM} | 7 | SIGNAL=${1:-SIGTERM} |
| 8 | COMMAND="$2" | 8 | COMMAND_START="$2" |
| 9 | COMMAND_EXIT="$3" | ||
| 9 | 10 | ||
| 10 | # If SIGNAL is received, switch to next display | 11 | # If SIGNAL is received, switch to next display |
| 11 | trap 'next_display' "$SIGNAL" | 12 | trap 'next_display' "$SIGNAL" |
| @@ -34,8 +35,8 @@ toggle_timer() { | |||
| 34 | read -p '? ' -r input | 35 | read -p '? ' -r input |
| 35 | # Disable input on terminal | 36 | # Disable input on terminal |
| 36 | stty -echo | 37 | stty -echo |
| 37 | # If COMMAND is given, run it after timer is set | 38 | # If COMMAND_START is given, run it after timer is set |
| 38 | result="$([ -n "$COMMAND" ] && eval "$COMMAND" 2>&1)" | 39 | result="$([ -n "$COMMAND_START" ] && eval "$COMMAND_START" 2>&1)" |
| 39 | notify-send "$result" &>/tmp/openbox | 40 | notify-send "$result" &>/tmp/openbox |
| 40 | 41 | ||
| 41 | 42 | ||
| @@ -78,7 +79,7 @@ timer() { | |||
| 78 | done | 79 | done |
| 79 | } | 80 | } |
| 80 | 81 | ||
| 81 | trap 'exec 1>&3; echo $count; send-notify foo' EXIT KILL TERM STOP | 82 | trap 'exec 1>&3; [ -n "COMMAND_EXIT" ] && eval "$COMMAND_EXIT"' EXIT QUIT HUP |
| 82 | 83 | ||
| 83 | while [ $count -lt $SET ]; do | 84 | while [ $count -lt $SET ]; do |
| 84 | [ $stop = true ] && sleep 0.3 && continue | 85 | [ $stop = true ] && sleep 0.3 && continue |