aboutsummaryrefslogtreecommitdiff
path: root/libexec/recit-edit-entry
blob: 1ee3d4e0cafb59a4539898970e9c7ceb498ff082 (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
#!/usr/bin/env bash
# Usage: recit edit-entry uuid
# Summary: Edit an entry given its UUID

set -e

recfile=$(recit-file)

uuid=""
if [[ "$1" = "-" ]]; then
  uuid=$(cat)
else
  uuid="$1"
fi

notes=$(recsel -e "Id = '$uuid'" -t Entry -P Notes "${recfile}")
time=$(recsel -e "Id = '$uuid'" -t Entry -P Time "${recfile}")

if [[ -z $notes ]]; then
  echo "record not found"
  exit 1
fi

if [[ -z ${EDITOR+x} ]]; then
  echo "$EDITOR is not defined please pass a message"
  exit 1
fi

tmpfile="$(mktemp)"
echo "$notes" > $tmpfile
command $EDITOR "$tmpfile"
notes=$(cat "$tmpfile")
rm "$tmpfile"

recins -e "Id = '$uuid'" -t Entry -f Id -v "$uuid" -f Notes -v "$notes" -f Time -v "$time" "${recfile}"