Added preview support

Also, removed unused function, and renamed a function.
This commit is contained in:
2025-05-21 17:14:17 +02:00
parent 8cd4dedb03
commit e8cf2751c3

View File

@@ -22,7 +22,7 @@ for label in "${COLLECTION_LABELS[@]}"; do
[[ ${#label} -gt $COLLECTION_LABEL_MAX_LEN ]] && COLLECTION_LABEL_MAX_LEN=${#label}
done
__vjourupdate() {
__vjournalupdate() {
python3 -c '
import sys
from datetime import datetime
@@ -227,13 +227,22 @@ __filepath_from_selection() {
echo -e "$selection"
}
__open_vj_file() {
local file="$1"
local tmpfile="$(mktemp).md"
echo "$file" | __vjournal2json
}
# Program starts here
selection=$(__lines | fzf --ansi)
# Command line arguments to be self-contained
# Generate preview of file from selection
if [[ "${1:-}" == "--preview" ]]; then
local vjfile=$(__filepath_from_selection "$2")
cat "$vjfile" | __vjournal2json | jq -r ".description" | batcat --color=always --style=numbers --language=md
exit
fi
selection=$(__lines | fzf --ansi --preview="$0 --preview {}"
#--bind='ctrl-d:execute(rm -i $(echo {}|$HOME/.zsh/journaling/filefromline))' \
#--bind='ctrl-n:execute($HOME/.zsh/journaling/add)' \
#--bind='ctrl-s:execute(vdirsyncer sync journals)' \
#--preview='vjour2json < $(echo {}|$HOME/.zsh/journaling/filefromline) | jq -r ".description" | batcat --color=always --style=numbers --language=md')
)
if [[ -z "$selection" ]]; then
return 0;
fi
@@ -271,7 +280,7 @@ then
echo "Uh... chages detected!"
local vj_file_new="$TMPFILE.ics"
trap "rm -f $vj_file_new" EXIT
__vjourupdate "$VJ_FILE" < "$TMPFILE" > "$vj_file_new" && mv "$vj_file_new" "$VJ_FILE"
__vjournalupdate "$VJ_FILE" < "$TMPFILE" > "$vj_file_new" && mv "$vj_file_new" "$VJ_FILE"
fi
exec "$0"