Compare commits

...

3 Commits

11 changed files with 397 additions and 85 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
fzf-vjour
demo/

View File

@@ -11,6 +11,12 @@ These entries are stored as [iCalendar](https://datatracker.ietf.org/doc/html/rf
For instance, you could use this application as a terminal-based counterpart of [jtx Board](https://jtx.techbee.at/) in a setup
with a CalDav server, such as [Radicale](https://radicale.org/), and a synchronization tool like [vdirsyncer](http://vdirsyncer.pimutils.org/).
Demo
----
Run the script `./scripts/generate_demo.sh` to generate a demo.
![Demo screenshot](./demo/screenshot.png)
Installation
------------

BIN
demo/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 106 KiB

56
scripts/generate_demo.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/bin/sh
set -eu
BOLD="\033[1m"
GREEN="\033[0;32m"
OFF="\033[m"
DEMO="demo"
FVJ="./fzf-vjour"
ROOT="$DEMO/journal/"
COLLECTION_LABELS="745ae7a0-d723-4cd8-80c4-75f52f5b7d90=shared 👫🏼;12cacb18-d3e1-4ad4-a1d0-e5b209012e85=work 💼;"
export CONFIGFILE="$DEMO/config"
rm -rf "$ROOT"
collection1="$(printf "%s" "$COLLECTION_LABELS" | cut -d ";" -f 1 | cut -d "=" -f 1)"
collection2="$(printf "%s" "$COLLECTION_LABELS" | cut -d ";" -f 2 | cut -d "=" -f 1)"
mkdir -p "$ROOT/$collection1"
mkdir -p "$ROOT/$collection2"
cat <<EOF >"$CONFIGFILE"
ROOT="$ROOT"
COLLECTION_LABELS="$COLLECTION_LABELS"
EOF
echo "⚙️ ${BOLD}${GREEN}Building demo$OFF"
## Fill in data
cal 2028 | $FVJ --add-note "2028 will be a leap year"
$FVJ --add-task "Finish proof of admissibility theorem" "tomorrow" --collection 2
cat <<EOF | $FVJ --add-task "Respond to referee report" "yesterday" --collection 2
- [x] Report 1: Answer prepared
- [ ] Report 2: Write response, revise manuscript
EOF
echo "Chinese" | $FVJ --add-task "Reserve dinner table" "next Sunday"
cat <<EOF | $FVJ --add-jour "Demo Coding"
### Demo code
Our demo now contains a script that self-generets the demo.
It's located in \`./scripts/\`
There are some upcoming steps:
1. Generate screenshot
2. Demonstrate attachment window
3. Extend code to handle timezones and alarms
EOF
cat <<EOF | $FVJ --add-note "Shopping list"
- [ ] Banana
- [ ] Bread
- [ ] Yoghurt
EOF
cat <<EOF | $FVJ --add-jour "Today's code" --collection 2
# Source code of current program
$(cat "$0")
EOF
$FVJ --add-task "Look for typos in readme" --collection 2 <"README.md"
## End of data
echo "🚀 ${BOLD}${GREEN}DONE.$OFF"
echo ""
echo "${GREEN}Run '${OFF}CONFIGFILE=$CONFIGFILE $FVJ$GREEN' to start demo$OFF"

View File

@@ -35,12 +35,34 @@ __lines() {
# Program starts here
if [ "${1:-}" = "--help" ]; then
bn="$(basename "$0")"
shift
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
--help Show this help and exit
--new Create new entry and do not exit
--git-init Activate git usage and exit
--git <cmd> Run git command and exit
echo "Usage: $bn [OPTION] [FILTER]...
[OPTION]
--help Show this help and exit
Git Integration:
--git-init Activate git usage and exit
--git <cmd> Run git command and exit
Interactive Mode:
--new [FILTER..] Create new entry interactively and start
[FILTER..] Start with the specified filter
Non-Interactive Mode:
--list [FILTER..] List entries and exit
--add-note <summary> Read note from stdin and add it with the
specified summary
--add-task <summary> [<due>] Read task from stdin and add it with the
specified summary and optional due date
--add-jour <summary> Read journal from stdin and add it with the
specified summary
--collection <nr> Select collection to which the note, task, or
journal entry is added non-interactively. The
argument <nr> is the ordinal describing the
collection. It defaults to the starting value
of 1.
[FILTER]
You may specify any of these filters. Filters can be negated using the
@@ -49,12 +71,22 @@ if [ "${1:-}" = "--help" ]; then
--no-completed is not the same as --open, and similarly, --no-open is not the
same as --completed.
--tasks Show tasks only
--notes Show notes only
--journal Show jounral only
--completed Show completed tasks only
--open Show open tasks only
--filter <query> Specify custom query"
--tasks Show tasks only
--notes Show notes only
--journal Show journal only
--completed Show completed tasks only
--open Show open tasks only
--filter <query> Specify custom query
Examples:
$bn --git log
$bn --new
$bn --journal
$bn --no-tasks --filter \"Beauregard\"
$bn --list --open
$bn --add-task \"Improve code to respect timezone information\" \"next month\"
cat proof.tex | $bn --add-journal \"Proof of Fixed-point Theorem\" --collection 2
"
exit
fi
@@ -64,19 +96,33 @@ fi
# Command line arguments: Interal use
. "sh/cliinternal.sh"
# Command line arguments: Interal use
# Command line arguments
. "sh/cli.sh"
# Parse command-line filter (if any)
. "sh/filter.sh"
# Attachment handling
. "sh/attachment.sh"
# Categories handling
. "sh/categories.sh"
if [ -n "${list_option:-}" ]; then
__lines |
$FZF \
--filter="$query" \
--no-sort \
--with-nth=5.. |
tac
exit 0
fi
while true; do
query=$(stripws "$query")
selection=$(
__lines | $FZF --ansi \
__lines | $FZF \
--ansi \
--query="$query " \
--no-sort \
--no-hscroll \

View File

@@ -5,7 +5,9 @@ __add_attachment() {
file="$1"
shift
sel=$(
$FZF --prompt="Select attachment> " \
$FZF \
--ansi \
--prompt="Select attachment> " \
--walker="file,hidden" \
--walker-root="$HOME" \
--expect="ctrl-c,ctrl-g,ctrl-q,esc"
@@ -137,6 +139,7 @@ __attachment_view() {
att=$(
awk "$AWK_ATTACHLS" "$file" |
$FZF \
--ansi \
--delimiter="\t" \
--accept-nth=1,2,3,4 \
--with-nth="Attachment {1}: \"{2}\" {3} ({5})" \

View File

@@ -7,7 +7,9 @@ __select_category() {
sort |
uniq |
grep '.' |
$FZF --prompt="Select category> " \
$FZF \
--ansi \
--prompt="Select category> " \
--no-sort \
--tac \
--margin="30%,30%" \

View File

@@ -1,5 +1,5 @@
# Git
if [ "${1:-}" = "--git-init" ]; then
case "${1:-}" in
"--git-init")
shift
if [ -n "${GIT:-}" ]; then
err "Git already enabled"
@@ -13,9 +13,8 @@ if [ "${1:-}" = "--git-init" ]; then
git -C "$ROOT" add -A
git -C "$ROOT" commit -m 'Initial commit: Start git tracking'
exit
fi
if [ "${1:-}" = "--git" ]; then
;;
"--git")
shift
if [ -z "${GIT:-}" ]; then
err "Git not supported, run \`$0 --git-init\` first"
@@ -23,72 +22,101 @@ if [ "${1:-}" = "--git" ]; then
fi
$GIT "$@"
exit
fi
# Generate new entry
if [ "${1:-}" = "--new" ]; then
;;
"--new")
shift
__new
fi
export next_filter=1
;;
"--list")
shift
export next_filter=1
export list_option=1
;;
esac
# Build query
while [ -n "${1:-}" ]; do
if [ -z "${next_filter:-}" ]; then
# else [FILTER] are the next options
# Here, we have --add-xyz with --collection or nothign
case "${1:-}" in
"--completed")
shift
cliquery="${cliquery:-} $FLAG_COMPLETED"
;;
"--no-completed")
shift
cliquery="${cliquery:-} !$FLAG_COMPLETED"
;;
"--open")
shift
cliquery="${cliquery:-} $FLAG_OPEN"
;;
"--no-open")
shift
cliquery="${cliquery:-} !$FLAG_OPEN"
;;
"--tasks")
shift
cliquery="${cliquery:-} $FLAG_OPEN | $FLAG_COMPLETED"
;;
"--no-tasks")
shift
cliquery="${cliquery:-} !$FLAG_COMPLETED !$FLAG_OPEN"
;;
"--notes")
shift
cliquery="${cliquery:-} $FLAG_NOTE"
;;
"--no-notes")
shift
cliquery="${cliquery:-} !$FLAG_NOTE"
;;
"--journal")
shift
cliquery="${cliquery:-} $FLAG_JOURNAL"
;;
"--no-journal")
shift
cliquery="${cliquery:-} !$FLAG_JOURNAL"
;;
"--filter")
shift
cliquery="${cliquery:-} $1"
shift
;;
"--no-filter")
shift
cliquery="${cliquery:-} !$1"
shift
;;
*)
err "Unknown option \"$1\""
exit 1
"--add-note" | "--add-task" | "--add-jour" | "--collection")
noninteractive=1
;;
esac
done
query=${cliquery:-!$FLAG_COMPLETED}
export query
if [ -n "${noninteractive:-}" ]; then
while [ -n "${1:-}" ]; do
case "$1" in
"--add-note" | "--add-task" | "--add-jour")
if [ -n "${add_option:-}" ]; then
err "What do you want to add?"
exit 1
fi
add_option="$1"
shift
summary=${1-}
if [ -z "$summary" ]; then
err "You did not give a summary"
exit 1
fi
shift
if [ "$add_option" = "--add-task" ] && [ -n "${1:-}" ]; then
case "$1" in
"--"*)
continue
;;
*)
due=$(printf "%s" "$1" | tr -dc "[:alnum:][:blank:]")
shift
if [ -z "$due" ] || ! date -d "$due" >/dev/null 2>&1; then
err "Invalid due date"
exit 1
fi
;;
esac
fi
;;
"--collection")
shift
collection="$(printf "%s" "$COLLECTION_LABELS" |
cut -d ";" -f "${1:-}" 2>/dev/null |
cut -d "=" -f 1 2>/dev/null)"
if [ -z "$collection" ]; then
err "Invalid collection"
exit 1
fi
shift
;;
*)
err "Unknown non-interactive option: $1"
exit 1
;;
esac
done
fi
fi
if [ -n "${noninteractive:-}" ]; then
if [ -z "${add_option:-}" ]; then
err "Specified collection, but nothing to add"
exit 1
fi
if [ -z "${collection:-}" ]; then
collection="$(
printf "%s" "$COLLECTION_LABELS" |
cut -d ";" -f 1 |
cut -d "=" -f 1
)"
fi
case "$add_option" in
"--add-note")
__add_note "$collection" "$summary"
;;
"--add-task")
__add_task "$collection" "$summary" "${due:-}"
;;
"--add-jour")
__add_jour "$collection" "$summary"
;;
esac
exit 0
fi

View File

@@ -6,7 +6,11 @@ fi
# shellcheck source=/dev/null
. "$CONFIGFILE"
if [ -z "${ROOT:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
err "Configuration is incomplete."
err "Configuration '$CONFIGFILE' is incomplete."
exit 1
fi
if [ ! -d "$ROOT" ]; then
err "Directory '$ROOT' does not exist."
exit 1
fi
SYNC_CMD="${SYNC_CMD:-}"
@@ -14,7 +18,12 @@ export ROOT
export SYNC_CMD
export COLLECTION_LABELS
for i in $(seq 9); do
collection=$(printf "%s" "$COLLECTION_LABELS" | cut -d ';' -f "$i" | cut -d '=' -f 1)
label=$(printf "%s" "$COLLECTION_LABELS" | cut -d ';' -f "$i" | cut -d '=' -f 2)
if [ -n "$label" ] && [ ! -d "$ROOT/$collection" ]; then
err "Collection directory for '$label' does not exist."
exit 1
fi
if [ -z "$label" ]; then
export COLLECTION_COUNT=$((i - 1))
break
@@ -24,7 +33,7 @@ done
# Tools
if command -v "fzf" >/dev/null; then
FZF="fzf"
FZF="fzf --black"
else
err "Did not find the command-line fuzzy finder fzf."
exit 1

61
src/sh/filter.sh Normal file
View File

@@ -0,0 +1,61 @@
# Build query
while [ -n "${1:-}" ]; do
case "${1:-}" in
"--completed")
shift
cliquery="${cliquery:-} $FLAG_COMPLETED"
;;
"--no-completed")
shift
cliquery="${cliquery:-} !$FLAG_COMPLETED"
;;
"--open")
shift
cliquery="${cliquery:-} $FLAG_OPEN"
;;
"--no-open")
shift
cliquery="${cliquery:-} !$FLAG_OPEN"
;;
"--tasks")
shift
cliquery="${cliquery:-} $FLAG_OPEN | $FLAG_COMPLETED"
;;
"--no-tasks")
shift
cliquery="${cliquery:-} !$FLAG_COMPLETED !$FLAG_OPEN"
;;
"--notes")
shift
cliquery="${cliquery:-} $FLAG_NOTE"
;;
"--no-notes")
shift
cliquery="${cliquery:-} !$FLAG_NOTE"
;;
"--journal")
shift
cliquery="${cliquery:-} $FLAG_JOURNAL"
;;
"--no-journal")
shift
cliquery="${cliquery:-} !$FLAG_JOURNAL"
;;
"--filter")
shift
cliquery="${cliquery:-} $1"
shift
;;
"--no-filter")
shift
cliquery="${cliquery:-} !$1"
shift
;;
*)
err "Unknown option \"$1\""
exit 1
;;
esac
done
query=${cliquery:-!$FLAG_COMPLETED}
export query

View File

@@ -1,5 +1,100 @@
# Interface to modify iCalendar files
# Wrapper to add entry from markdown file
#
# @input $1: path to markdown file
# @input $2: collection to add to
__add_from_md() {
tmpmd="$1"
shift
collection="$1"
shift
file=""
while [ -f "$file" ] || [ -z "$file" ]; do
uuid=$($UUIDGEN)
file="$ROOT/$collection/$uuid.ics"
done
tmpfile="$tmpmd.ics"
if awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"; then
if [ ! -d "$ROOT/$collection" ]; then
mkdir -p "$ROOT/$collection"
fi
mv "$tmpfile" "$file"
if [ -n "${GIT:-}" ]; then
$GIT add "$file"
$GIT commit -q -m "File added" -- "$file"
fi
else
rm -f "$tmpfile"
err "Failed to create new entry."
fi
rm "$tmpmd"
}
# Noninteractively add note, and fill description from stdin
#
# @input $1: Collection
# @input $2: Summary
__add_note() {
collection="$1"
shift
summary="$1"
shift
tmpmd=$(mktemp --suffix='.md')
{
echo "# $summary"
echo ""
} >"$tmpmd"
if [ ! -t 0 ]; then
cat /dev/stdin >>"$tmpmd"
fi
__add_from_md "$tmpmd" "$collection"
}
# Noninteractively add task, and fill description from stdin
#
# @input $1: Collection
# @input $2: Summary
# @input $3: Due date (optional)
__add_task() {
collection="$1"
shift
summary="$1"
shift
due="${1:-}"
tmpmd=$(mktemp --suffix='.md')
{
echo "::: <| $due"
echo "# $summary"
echo ""
} >"$tmpmd"
if [ ! -t 0 ]; then
cat /dev/stdin >>"$tmpmd"
fi
__add_from_md "$tmpmd" "$collection"
}
# Noninteractively add jounral, and fill description from stdin
#
# @input $1: Collection
# @input $2: Summary
__add_jour() {
collection="$1"
shift
summary="$1"
shift
tmpmd=$(mktemp --suffix='.md')
{
echo "::: |> <!-- keep this line to associate the entry to _today_ -->"
echo "# $summary"
echo ""
} >"$tmpmd"
if [ ! -t 0 ]; then
cat /dev/stdin >>"$tmpmd"
fi
__add_from_md "$tmpmd" "$collection"
}
# Toggle completed status of VTODO
#
# @input $1: Relative path to iCalendar file
@@ -112,7 +207,9 @@ __new() {
collection=$(printf "%s" "$COLLECTION_LABELS" |
tr ';' '\n' |
$FZF \
--ansi \
--prompt="Choose collection> " \
--select-1 \
--no-sort \
--tac \
--margin="30%,30%" \
@@ -146,6 +243,9 @@ __new() {
while [ "$checksum" != "$(cksum "$tmpmd")" ]; do
tmpfile="$tmpmd.ics"
if awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"; then
if [ ! -d "$ROOT/$collection" ]; then
mkdir -p "$ROOT/$collection"
fi
mv "$tmpfile" "$file"
if [ -n "${GIT:-}" ]; then
$GIT add "$file"