aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/task/context
blob: d81573b6c166852f574dc21e4f6b61288a92dbfc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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