Compare commits
2 Commits
0c742eccd4
...
7df51a6980
| Author | SHA1 | Date | |
|---|---|---|---|
| 7df51a6980 | |||
| 4079a53c2b |
@@ -10,7 +10,8 @@ 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.
|
||||||
|
|||||||
53
src/main.sh
53
src/main.sh
@@ -2,13 +2,36 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
err() {
|
||||||
|
echo "❌ $1" >/dev/tty
|
||||||
|
}
|
||||||
# Read configuration
|
# Read configuration
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$HOME/.config/fzf-vjour/config"
|
CONFIGFILE="$HOME/.config/fzf-vjour/config"
|
||||||
if [ -z "$ROOT" ] || [ -z "$SYNC_CMD" ] || [ -z "$COLLECTION_LABELS" ]; then
|
if [ ! -f "$CONFIGFILE" ]; then
|
||||||
echo "Failed to get configuration." >/dev/tty
|
err "Configuration '$CONFIGFILE' not found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
. "$CONFIGFILE"
|
||||||
|
if [ -z "${ROOT:-}" ] || [ -z "${SYNC_CMD:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
|
||||||
|
err "Configuration is incomplete."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Tools
|
||||||
|
if command -v "fzf" >/dev/null; then
|
||||||
|
FZF="fzf"
|
||||||
|
else
|
||||||
|
err "Did not find the command-line fuzzy finder fzf."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
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}
|
||||||
|
|
||||||
### AWK SCRIPTS
|
### AWK SCRIPTS
|
||||||
AWK_ALTERTODO=$(
|
AWK_ALTERTODO=$(
|
||||||
@@ -96,7 +119,7 @@ fi
|
|||||||
if [ "${1:-}" = "--preview" ]; then
|
if [ "${1:-}" = "--preview" ]; then
|
||||||
file=$(__filepath_from_selection "$2")
|
file=$(__filepath_from_selection "$2")
|
||||||
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
|
||||||
@@ -104,7 +127,7 @@ if [ "${1:-}" = "--delete" ]; then
|
|||||||
file=$(__filepath_from_selection "$2")
|
file=$(__filepath_from_selection "$2")
|
||||||
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")
|
||||||
@@ -124,7 +147,7 @@ fi
|
|||||||
if [ "${1:-}" = "--new" ]; then
|
if [ "${1:-}" = "--new" ]; then
|
||||||
label=$(printf "%s" "$COLLECTION_LABELS" |
|
label=$(printf "%s" "$COLLECTION_LABELS" |
|
||||||
awk 'BEGIN { FS="="; RS=";"; } {print $2}' |
|
awk 'BEGIN { FS="="; RS=";"; } {print $2}' |
|
||||||
fzf \
|
$FZF \
|
||||||
--margin 20% \
|
--margin 20% \
|
||||||
--prompt="Select collection> ")
|
--prompt="Select collection> ")
|
||||||
|
|
||||||
@@ -136,7 +159,6 @@ if [ "${1:-}" = "--new" ]; then
|
|||||||
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,18 +166,18 @@ 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
|
||||||
@@ -214,7 +236,7 @@ fi
|
|||||||
query=$(echo "$query" | sed 's/ *$//g')
|
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 \
|
||||||
@@ -230,7 +252,7 @@ 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 ; echo 'Press <enter> to continue.'; read -r tmp)"
|
||||||
)
|
)
|
||||||
if [ -z "$selection" ]; then
|
if [ -z "$selection" ]; then
|
||||||
return 0
|
return 0
|
||||||
@@ -245,20 +267,19 @@ 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
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user