Compare commits

..

8 Commits

3 changed files with 127 additions and 74 deletions

View File

@@ -1,4 +1,7 @@
A [fzf](https://github.com/junegunn/fzf)-based **journaling, notes, and tasks** application with CalDav support. A [fzf](https://github.com/junegunn/fzf)-based **journaling, notes, and tasks** application with CalDav support.
If you are interested in this, then you may also be interested in the
corresponding calendar application
[fzf-vcal](https://github.com/baumea/fzf-vcal).
Description and Use Case Description and Use Case
------------------------ ------------------------
@@ -10,11 +13,13 @@ with a CalDav server, such as [Radicale](https://radicale.org/), and a synchroni
Installation Installation
------------ ------------
Just copy the file to your preferred location, e.g., `~/.local/bin`, and make it executable. Download the file `fzf-vjour` from the [latest release](https://github.com/baumea/fzf-vjour/releases/latest), or run `./scripts/build.sh`, then
copy `fzf-vjour` to your preferred location, e.g., `~/.local/bin`, and make it executable.
### Requirements ### Requirements
This is a POSIX script with inline `awk` elements. This is a POSIX script with inline `awk` elements.
Make sure you have [fzf](https://github.com/junegunn/fzf) and [batcat](https://github.com/sharkdp/bat). Make sure you have [fzf](https://github.com/junegunn/fzf) installed.
I also suggest to install [batcat](https://github.com/sharkdp/bat) for colorful previews.
Configuration Configuration
-------------- --------------

View File

@@ -130,6 +130,21 @@ ENDFILE {
if (!type) { if (!type) {
exit exit
} }
# Construct path, and check for validity
depth = split(FILENAME, path, "/");
fpath = path[depth-1] "/" path[depth]
if (index(fpath, " "))
{
print 10,
"-",
"-",
RED "ERROR: file '" fpath "' contains whitespaces!" OFF
exit
}
# Collection name
collection = path[depth-1]
collection = collection in collection2label ? collection2label[collection] : collection;
# Process content lines # Process content lines
storetext_line(content_line, c, "CATEGORIES" ); storetext_line(content_line, c, "CATEGORIES" );
storetext_line(content_line, c, "DESCRIPTION" ); storetext_line(content_line, c, "DESCRIPTION" );
@@ -160,11 +175,6 @@ ENDFILE {
# format # format
mod = c["LAST-MODIFIED"] ? c["LAST-MODIFIED"] : c["DTSTAMP"]; mod = c["LAST-MODIFIED"] ? c["LAST-MODIFIED"] : c["DTSTAMP"];
# Collection name
depth = split(FILENAME, path, "/");
collection = depth > 1 ? path[depth-1] : "";
collection = collection in collection2label ? collection2label[collection] : collection;
# Date field. For VTODO entries, we show the due date, for journal entries, # Date field. For VTODO entries, we show the due date, for journal entries,
# the associated date. # the associated date.
datecolor = CYAN; datecolor = CYAN;
@@ -206,10 +216,10 @@ ENDFILE {
print prio, print prio,
mod, mod,
fpath,
collection, collection,
datecolor d OFF, datecolor d OFF,
flag, flag,
priotext summarycolor summary OFF, priotext summarycolor summary OFF,
WHITE categories OFF, WHITE categories OFF;
" " FAINT FILENAME OFF;
} }

View File

@@ -2,13 +2,52 @@
set -eu set -eu
err() {
echo "$1" >/dev/tty
}
if [ -z "${FZF_VJOUR_USE_EXPORTED:-}" ]; then
# Read configuration # Read configuration
# shellcheck source=/dev/null CONFIGFILE="$HOME/.config/fzf-vjour/config"
. "$HOME/.config/fzf-vjour/config" if [ ! -f "$CONFIGFILE" ]; then
if [ -z "$ROOT" ] || [ -z "$SYNC_CMD" ] || [ -z "$COLLECTION_LABELS" ]; then err "Configuration '$CONFIGFILE' not found."
echo "Failed to get configuration." >/dev/tty
exit 1 exit 1
fi fi
# shellcheck source=/dev/null
. "$CONFIGFILE"
if [ -z "${ROOT:-}" ] || [ -z "${SYNC_CMD:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
err "Configuration is incomplete."
exit 1
fi
export ROOT
export SYNC_CMD
export COLLECTION_LABELS
# Tools
if command -v "fzf" >/dev/null; then
FZF="fzf"
else
err "Did not find the command-line fuzzy finder fzf."
exit 1
fi
export FZF
if command -v "uuidgen" >/dev/null; then
UUIDGEN="uuidgen"
else
err "Did not find the uuidgen command."
exit 1
fi
export UUIDGEN
if command -v "bat" >/dev/null; then
CAT="bat"
elif command -v "batcat" >/dev/null; then
CAT="batcat"
fi
CAT=${CAT:+$CAT --color=always --style=numbers --language=md}
CAT=${CAT:-cat}
export CAT
### AWK SCRIPTS ### AWK SCRIPTS
AWK_ALTERTODO=$( AWK_ALTERTODO=$(
@@ -16,37 +55,46 @@ AWK_ALTERTODO=$(
@@include src/awk/altertodo.awk @@include src/awk/altertodo.awk
EOF EOF
) )
export AWK_ALTERTODO
AWK_EXPORT=$( AWK_EXPORT=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/export.awk @@include src/awk/export.awk
EOF EOF
) )
export AWK_EXPORT
AWK_GET=$( AWK_GET=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/get.awk @@include src/awk/get.awk
EOF EOF
) )
export AWK_GET
AWK_LIST=$( AWK_LIST=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/list.awk @@include src/awk/list.awk
EOF EOF
) )
export AWK_LIST
AWK_NEW=$( AWK_NEW=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/new.awk @@include src/awk/new.awk
EOF EOF
) )
export AWK_NEW
AWK_UPDATE=$( AWK_UPDATE=$(
cat <<'EOF' cat <<'EOF'
@@include src/awk/update.awk @@include src/awk/update.awk
EOF EOF
) )
export AWK_UPDATE
### END OF AWK SCRIPTS ### END OF AWK SCRIPTS
FZF_VJOUR_USE_EXPORTED="yes"
export FZF_VJOUR_USE_EXPORTED
fi
__lines() { __lines() {
find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \ find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \
@@ -57,12 +105,7 @@ __lines() {
-v flag_journal="📘" \ -v flag_journal="📘" \
-v flag_note="🗒️" \ -v flag_note="🗒️" \
"$AWK_LIST" | "$AWK_LIST" |
sort -g -r | sort -g -r
cut -d ' ' -f 3-
}
__filepath_from_selection() {
echo "$1" | grep -o ' \{50\}.*$' | xargs
} }
# Program starts here # Program starts here
@@ -94,17 +137,19 @@ fi
# Command line arguments to be self-contained # Command line arguments to be self-contained
# Generate preview of file from selection # Generate preview of file from selection
if [ "${1:-}" = "--preview" ]; then if [ "${1:-}" = "--preview" ]; then
file=$(__filepath_from_selection "$2") name=$(echo "$2" | cut -d ' ' -f 3)
file="$ROOT/$name"
awk -v field="DESCRIPTION" "$AWK_GET" "$file" | awk -v field="DESCRIPTION" "$AWK_GET" "$file" |
batcat --color=always --style=numbers --language=md $CAT
exit exit
fi fi
# Delete file from selection # Delete file from selection
if [ "${1:-}" = "--delete" ]; then if [ "${1:-}" = "--delete" ]; then
file=$(__filepath_from_selection "$2") name=$(echo "$2" | cut -d ' ' -f 3)
file="$ROOT/$name"
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file") summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file")
while true; do while true; do
printf "Do you want to delete the entry with the title \"%s\"? " "$summary" >/dev/tty printf "Do you want to delete the entry with the title \"%s\"? (yes/no): " "$summary" >/dev/tty
read -r yn read -r yn
case $yn in case $yn in
"yes") "yes")
@@ -122,21 +167,13 @@ if [ "${1:-}" = "--delete" ]; then
fi fi
# Generate new entry # Generate new entry
if [ "${1:-}" = "--new" ]; then if [ "${1:-}" = "--new" ]; then
label=$(printf "%s" "$COLLECTION_LABELS" | collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
awk 'BEGIN { FS="="; RS=";"; } {print $2}' |
fzf \
--margin 20% \
--prompt="Select collection> ")
collection=$(printf "%s" "$COLLECTION_LABELS" |
awk -v label="$label" 'BEGIN { FS="="; RS=";"; } $2 == label {print $1}')
file="" file=""
while [ -f "$file" ] || [ -z "$file" ]; do while [ -f "$file" ] || [ -z "$file" ]; do
uuid=$(uuidgen) uuid=$($UUIDGEN)
file="$ROOT/$collection/$uuid.ics" file="$ROOT/$collection/$uuid.ics"
done done
tmpmd=$(mktemp --suffix='.md') tmpmd=$(mktemp --suffix='.md')
tmpsha="$tmpmd.sha"
{ {
echo "::: |> <!-- keep this line to associate the entry to _today_ -->" echo "::: |> <!-- keep this line to associate the entry to _today_ -->"
echo "::: <| <!-- specify the due date for to-dos, can be empty, a date string, or even \"next Sunday\" -->" echo "::: <| <!-- specify the due date for to-dos, can be empty, a date string, or even \"next Sunday\" -->"
@@ -144,36 +181,39 @@ if [ "${1:-}" = "--new" ]; then
echo "> <!-- comma-separated list of categories -->" echo "> <!-- comma-separated list of categories -->"
echo "" echo ""
} >"$tmpmd" } >"$tmpmd"
sha1sum "$tmpmd" >"$tmpsha" checksum=$(cksum "$tmpmd")
# Open in editor # Open in editor
$EDITOR "$tmpmd" >/dev/tty $EDITOR "$tmpmd" >/dev/tty
# Update if changes are detected # Update if changes are detected
if ! sha1sum -c "$tmpsha" >/dev/null 2>&1; then if [ "$checksum" != "$(cksum "$tmpmd")" ]; then
tmpfile="$tmpmd.ics" tmpfile="$tmpmd.ics"
awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile" awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"
mv "$tmpfile" "$file" mv "$tmpfile" "$file"
fi fi
rm "$tmpmd" "$tmpsha" rm "$tmpmd"
fi fi
# Toggle completed flag # Toggle completed flag
if [ "${1:-}" = "--toggle-completed" ]; then if [ "${1:-}" = "--toggle-completed" ]; then
file=$(__filepath_from_selection "$2") name=$(echo "$2" | cut -d ' ' -f 3)
file="$ROOT/$name"
tmpfile=$(mktemp) tmpfile=$(mktemp)
awk "$AWK_ALTERTODO" "$file" >"$tmpfile" awk "$AWK_ALTERTODO" "$file" >"$tmpfile"
mv "$tmpfile" "$file" mv "$tmpfile" "$file"
fi fi
# Increase priority # Increase priority
if [ "${1:-}" = "--increase-priority" ]; then if [ "${1:-}" = "--increase-priority" ]; then
file=$(__filepath_from_selection "$2") name=$(echo "$2" | cut -d ' ' -f 3)
file="$ROOT/$name"
tmpfile=$(mktemp) tmpfile=$(mktemp)
awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile" awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
mv "$tmpfile" "$file" mv "$tmpfile" "$file"
fi fi
# Decrease priority # Decrease priority
if [ "${1:-}" = "--decrease-priority" ]; then if [ "${1:-}" = "--decrease-priority" ]; then
file=$(__filepath_from_selection "$2") name=$(echo "$2" | cut -d ' ' -f 3)
file="$ROOT/$name"
tmpfile=$(mktemp) tmpfile=$(mktemp)
awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile" awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
mv "$tmpfile" "$file" mv "$tmpfile" "$file"
@@ -208,17 +248,17 @@ fi
if [ "${1:-}" = "--no-journal" ]; then if [ "${1:-}" = "--no-journal" ]; then
query="!📘" query="!📘"
fi fi
if [ -z "$query" ]; then query=${query:-!✅}
query="!✅" query=$(echo "$query" | xargs)
fi
query=$(echo "$query" | sed 's/ *$//g')
selection=$( selection=$(
__lines | fzf --ansi \ __lines | $FZF --ansi \
--query="$query " \ --query="$query " \
--no-sort \ --no-sort \
--no-hscroll \ --no-hscroll \
--ellipsis='' \ --ellipsis='' \
--with-nth=4.. \
--accept-nth=3 \
--preview="$0 --preview {}" \ --preview="$0 --preview {}" \
--bind="ctrl-r:reload-sync($0 --reload)" \ --bind="ctrl-r:reload-sync($0 --reload)" \
--bind="ctrl-alt-d:become($0 --delete {})" \ --bind="ctrl-alt-d:become($0 --delete {})" \
@@ -230,13 +270,13 @@ selection=$(
--bind="alt-1:change-query(📘)" \ --bind="alt-1:change-query(📘)" \
--bind="alt-2:change-query(🗒️)" \ --bind="alt-2:change-query(🗒️)" \
--bind="alt-3:change-query(✅ | 🔲)" \ --bind="alt-3:change-query(✅ | 🔲)" \
--bind="ctrl-s:execute($SYNC_CMD)" --bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)"
) )
if [ -z "$selection" ]; then if [ -z "$selection" ]; then
return 0 return 0
fi fi
file=$(__filepath_from_selection "$selection") file="$ROOT/$selection"
if [ ! -f "$file" ]; then if [ ! -f "$file" ]; then
echo "ERROR: File '$file' does not exist!" >/dev/tty echo "ERROR: File '$file' does not exist!" >/dev/tty
@@ -245,20 +285,18 @@ fi
# Prepare file to be edited # Prepare file to be edited
filetmp=$(mktemp --suffix='.md') filetmp=$(mktemp --suffix='.md')
filesha="$filetmp.sha"
awk "$AWK_EXPORT" "$file" >"$filetmp" awk "$AWK_EXPORT" "$file" >"$filetmp"
sha1sum "$filetmp" >"$filesha" checksum=$(cksum "$filetmp")
# Open in editor # Open in editor
$EDITOR "$filetmp" >/dev/tty $EDITOR "$filetmp" >/dev/tty
# Update only if changes are detected # Update only if changes are detected
if ! sha1sum -c "$filesha" >/dev/null 2>&1; then if [ "$checksum" != "$(cksum "$filetmp")" ]; then
echo "Uh... chages detected!" >/dev/tty
file_new="$filetmp.ics" file_new="$filetmp.ics"
awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new" awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
mv "$file_new" "$file" mv "$file_new" "$file"
fi fi
rm "$filetmp" "$filesha" rm "$filetmp"
exec "$0" exec "$0"