diff options
author | Julio Capote <jcapote@gmail.com> | 2022-08-21 02:44:05 +0000 |
---|---|---|
committer | Julio Capote <jcapote@gmail.com> | 2022-08-21 02:44:05 +0000 |
commit | bf922c47dedde37e3d97c4bf82f38e7d769fa267 (patch) | |
tree | 14c2c8a17250f93a0248bd9b887fa8562c26a345 /libexec/recit-entries | |
parent | 9e4f34a5989f6be48eaaebf17c8e42e61ebf3d76 (diff) | |
download | recit-bf922c47dedde37e3d97c4bf82f38e7d769fa267.tar.gz |
move tomorrow/yesterday/today to entries
Diffstat (limited to '')
-rwxr-xr-x | libexec/recit-entries | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/libexec/recit-entries b/libexec/recit-entries index 343006d..dd495d8 100755 --- a/libexec/recit-entries +++ b/libexec/recit-entries @@ -1,5 +1,7 @@ #!/usr/bin/env bash -# Usage: recit entries [-p project-name] +# Usage: recit entries [-p project-name] [-t time|today|yesterday|tomorrow] + +set -xe # shellcheck source=/dev/null source lib/loader @@ -7,13 +9,17 @@ source lib/loader recfile=$(load_recit) project="" +query_time="" -while getopts "p:" options; do +while getopts "p:t:" options; do case "${options}" in p) project=${OPTARG} ;; + t) + query_time=${OPTARG} + ;; :) echo "Error: -${OPTARG} requires an argument." exit 1 @@ -24,14 +30,36 @@ while getopts "p:" options; do esac done -if [[ "$project" = "" ]]; then - recsel -t Entry "${recfile}" -else +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 - recsel -e "ProjectRef = '$project'" -t Entry "${recfile}" + 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 +if [[ "$expression" = "" ]]; then + recsel -t Entry "${recfile}" +else + recsel -t Entry -e "$expression" "${recfile}" +fi |