#!/usr/bin/env bash # Usage: recit add-entry [-p project-name] [-t time|today|yesterday|tomorrow] [-m notes] # Summary: Add entries, optionally for a project and/or a certain time set -e # shellcheck source=/dev/null source lib/loader recfile=$(load_recit) notes="" query_time="" project="" while getopts "p:m:t:" options; do case "${options}" in p) project=${OPTARG} ;; m) notes=${OPTARG} ;; t) query_time=${OPTARG} ;; :) echo "Error: -${OPTARG} requires an argument." exit 1 ;; *) exit 1 ;; esac done uuid=$(uuidgen) if [[ "$query_time" = "" ]]; then query_time="now" fi if [[ "$notes" = "" ]]; then if [[ -z ${EDITOR+x} ]]; then echo "$EDITOR is not defined please pass a message with -m" exit 1 fi tmpfile="$(mktemp)" command $EDITOR "$tmpfile" notes=$(cat "$tmpfile") rm "$tmpfile" fi if [[ "$query_time" == "now" || "$query_time" == "today" ]]; then fmt_date=$(date '+%Y-%m-%d %r') elif [[ "$query_time" == "tomorrow" ]]; 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 if [[ "$project" = "" ]]; then recins --verbose -f Id -v "$uuid" -f Time -v "$fmt_date" -f Notes -v "$notes" -t Entry "${recfile}" echo "$uuid" else if recsel -t Project -p Id ${recfile} | grep "$project" > /dev/null; then recins --verbose -f Id -v "$uuid" -f Time -v "$fmt_date" -f Notes -v "$notes" -f ProjectRef -v "$project" -t Entry "${recfile}" echo "$uuid" else echo "$project not found, list of available projects:" recsel -t Project -p Id ${recfile} exit 1 fi fi