Added capability to add new entries
This commit is contained in:
94
fzf-vjour
94
fzf-vjour
@@ -22,6 +22,62 @@ for label in "${COLLECTION_LABELS[@]}"; do
|
|||||||
[[ ${#label} -gt $COLLECTION_LABEL_MAX_LEN ]] && COLLECTION_LABEL_MAX_LEN=${#label}
|
[[ ${#label} -gt $COLLECTION_LABEL_MAX_LEN ]] && COLLECTION_LABEL_MAX_LEN=${#label}
|
||||||
done
|
done
|
||||||
|
|
||||||
|
__vjournalnew() {
|
||||||
|
python3 -c '
|
||||||
|
import sys
|
||||||
|
from datetime import date, datetime
|
||||||
|
from icalendar.cal import Calendar, Journal
|
||||||
|
|
||||||
|
if not len(sys.argv) == 2:
|
||||||
|
print("Pass uid as first argument!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
UID = sys.argv[1]
|
||||||
|
ical = Calendar()
|
||||||
|
j = Journal()
|
||||||
|
|
||||||
|
isnote = True
|
||||||
|
line = sys.stdin.readline().strip()
|
||||||
|
if line[:4] == "::: ":
|
||||||
|
isnote = False
|
||||||
|
line = sys.stdin.readline().strip()
|
||||||
|
|
||||||
|
if not line[:2] == "# ":
|
||||||
|
print("Error: Summary line is corrupt!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
summary = line[2:]
|
||||||
|
|
||||||
|
line = sys.stdin.readline().strip()
|
||||||
|
if not line[:2] == "> " and not line == ">":
|
||||||
|
print("Error: Categories line is corrupt!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
categories = line[2:].split(",")
|
||||||
|
|
||||||
|
line = sys.stdin.readline().strip()
|
||||||
|
if not line == "":
|
||||||
|
print("Error: Missing separating line!", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
description = sys.stdin.read()
|
||||||
|
|
||||||
|
# Create ical
|
||||||
|
j["SUMMARY"] = summary
|
||||||
|
j.categories = categories
|
||||||
|
j["DESCRIPTION"] = description
|
||||||
|
j.LAST_MODIFIED = datetime.utcnow()
|
||||||
|
j.DTSTAMP = datetime.utcnow()
|
||||||
|
j["UID"] = UID
|
||||||
|
j["SEQUENCE"] = 1
|
||||||
|
j["STATUS"] = "FINAL"
|
||||||
|
if not isnote:
|
||||||
|
j.DTSTART = date.today()
|
||||||
|
ical.add_component(j)
|
||||||
|
ical["VERSION"] = "2.0"
|
||||||
|
ical["PRODID"] = "vjournew/basic"
|
||||||
|
|
||||||
|
# Print
|
||||||
|
print(ical.to_ical().decode().replace("\r\n", "\n"))' "$@"
|
||||||
|
}
|
||||||
__vjournalupdate() {
|
__vjournalupdate() {
|
||||||
python3 -c '
|
python3 -c '
|
||||||
import sys
|
import sys
|
||||||
@@ -242,11 +298,45 @@ if [[ "${1:-}" == "--delete" ]]; then
|
|||||||
rm -v "$vjfile"
|
rm -v "$vjfile"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
# Generate new entry
|
||||||
|
if [[ "${1:-}" == "--new" ]]; then
|
||||||
|
local label_new=$(for label in "${COLLECTION_LABELS[@]}"; do
|
||||||
|
echo "$label"
|
||||||
|
done | fzf --prompt="Select collection> ")
|
||||||
|
local uuid_new=$(uuidgen)
|
||||||
|
local vjfile_new=$(__filepath_from_selection "$label_new $uuid_new.ics")
|
||||||
|
if [[ -f "$vjfile_new" ]]
|
||||||
|
then
|
||||||
|
echo "Bad luck..."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
#
|
||||||
|
local TMPFILE="$(mktemp).md"
|
||||||
|
local SHAFILE="$TMPFILE.sha"
|
||||||
|
trap "rm -f $TMPFILE $SHAFILE" EXIT
|
||||||
|
echo "::: Keep this line if you want to add a **JOURNAL** entry (associated to today), else we will add a **NOTE**" > "$TMPFILE"
|
||||||
|
echo "# <write summary here>" >> "$TMPFILE"
|
||||||
|
echo "> <comma-separated list of categories>" >> "$TMPFILE"
|
||||||
|
echo >> "$TMPFILE"
|
||||||
|
sha1sum "$TMPFILE" > "$SHAFILE"
|
||||||
|
|
||||||
|
# Open in editor
|
||||||
|
$EDITOR "$TMPFILE"
|
||||||
|
|
||||||
|
# Update if changes are detected
|
||||||
|
if ! sha1sum -c "$SHAFILE" > /dev/null 2>&1
|
||||||
|
then
|
||||||
|
local vjfile_tmp="$TMPFILE.ics"
|
||||||
|
trap "rm -f $vjfile_tmp" EXIT
|
||||||
|
__vjournalnew "$uuid_new" < "$TMPFILE" > "$vjfile_tmp" && mv "$vjfile_tmp" "$vjfile_new"
|
||||||
|
fi
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
selection=$(__lines | fzf --ansi \
|
selection=$(__lines | fzf --ansi \
|
||||||
--preview="$0 --preview {}" \
|
--preview="$0 --preview {}" \
|
||||||
--bind="ctrl-d:execute($0 --delete {})"
|
--bind="ctrl-d:execute($0 --delete {})" \
|
||||||
#--bind='ctrl-n:execute($HOME/.zsh/journaling/add)' \
|
--bind="ctrl-n:execute($0 --new)"
|
||||||
#--bind='ctrl-s:execute(vdirsyncer sync journals)' \
|
#--bind='ctrl-s:execute(vdirsyncer sync journals)' \
|
||||||
)
|
)
|
||||||
if [[ -z "$selection" ]]; then
|
if [[ -z "$selection" ]]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user