aboutsummaryrefslogtreecommitdiff
path: root/libexec/recit-entries
blob: 388896321bef4f63e4087e125173115695080d76 (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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
# Usage: recit entries [-p project-name] [-t time|today|yesterday|tomorrow]
# Summary: Display entries, optionally for a project and/or a certain time
set -e

# shellcheck source=/dev/null
source lib/loader

recfile=$(load_recit)

project=""
query_time=""

while getopts "p:t:" options; do       
                                          
  case "${options}" in                    
    p)                                    
      project=${OPTARG}                      
      ;;
    t)                                    
      query_time=${OPTARG}                      
      ;;
    :)                                    
      echo "Error: -${OPTARG} requires an argument."
      exit 1
      ;;
    *)                   
      exit 1
      ;;
  esac
done

expression=""
if ! [[ "$query_time" = "" ]]; then
  if [[ "$query_time" = "today" ]]; then
    fmt_date=$(date '+%Y-%m-%d')
  elif [[ "$query_time" = "tomorrow" ]]; then
    fmt_date=$(perl -e "use POSIX qw(strftime); print strftime('%Y-%m-%d', localtime(time + 86400)), qq(\n);")
  elif [[ "$query_time" = "yesterday" ]]; then
    fmt_date=$(perl -e "use POSIX qw(strftime); print strftime('%Y-%m-%d', localtime(time - 86400)), qq(\n);")
  else
    fmt_date=$query_time
  fi
  expression="((Time >> '$fmt_date 00:00:00' && Time << '$fmt_date 23:59:59') || Time == '$fmt_date')"
fi

if ! [[ "$project" = "" ]]; then
  if recsel -t Project -p Id ${recfile} | grep "$project" > /dev/null; then
    if [[ "$expression" = "" ]]; then
      expression="ProjectRef = '$project'"
    else
      expression+=" && ProjectRef = '$project'"
    fi
  else
    echo "$project not found, list of available projects:"
    recsel -t Project -p Id ${recfile}
    exit 1
  fi
fi

recit-recsel-entries "$expression"

# if [[ "$expression" = "" ]]; then
#   out=$(recsel -t Entry "${recfile}" | recfmt -f share/recit/templates/entries.templ)
# else
#   out=$(recsel -t Entry "${recfile}" -e "$expression" | recfmt -f share/recit/templates/entries.templ)
# fi
# echo -e "$out"