aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/task/context_spend_time.sh31
-rwxr-xr-xbin/unix/timer.sh9
2 files changed, 36 insertions, 4 deletions
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
3LOG_FILE=~/log/context
4context="$(cat ~/.task/context)"
5count="$1"
6
7if [ -z "$context" ] || [ "$context" = none ]; then
8 exit 1
9fi
10
11if [ -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
25else
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
31fi
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
5exec 1>/dev/tty 5exec 1>/dev/tty
6 6
7SIGNAL=${1:-SIGTERM} 7SIGNAL=${1:-SIGTERM}
8COMMAND="$2" 8COMMAND_START="$2"
9COMMAND_EXIT="$3"
9 10
10# If SIGNAL is received, switch to next display 11# If SIGNAL is received, switch to next display
11trap 'next_display' "$SIGNAL" 12trap 'next_display' "$SIGNAL"
@@ -34,8 +35,8 @@ toggle_timer() {
34read -p '? ' -r input 35read -p '? ' -r input
35# Disable input on terminal 36# Disable input on terminal
36stty -echo 37stty -echo
37# If COMMAND is given, run it after timer is set 38# If COMMAND_START is given, run it after timer is set
38result="$([ -n "$COMMAND" ] && eval "$COMMAND" 2>&1)" 39result="$([ -n "$COMMAND_START" ] && eval "$COMMAND_START" 2>&1)"
39notify-send "$result" &>/tmp/openbox 40notify-send "$result" &>/tmp/openbox
40 41
41 42
@@ -78,7 +79,7 @@ timer() {
78 done 79 done
79} 80}
80 81
81trap 'exec 1>&3; echo $count; send-notify foo' EXIT KILL TERM STOP 82trap 'exec 1>&3; [ -n "COMMAND_EXIT" ] && eval "$COMMAND_EXIT"' EXIT QUIT HUP
82 83
83while [ $count -lt $SET ]; do 84while [ $count -lt $SET ]; do
84 [ $stop = true ] && sleep 0.3 && continue 85 [ $stop = true ] && sleep 0.3 && continue