Compare commits

...

16 Commits

18 changed files with 618 additions and 184 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
------------
@@ -72,6 +78,9 @@ item_types = ["VJOURNAL", "VTODO"]
You may also specify the location of the configuration file with the environment `CONFIGFILE`.
By default, `fzf-vjour` sets a descriptive terminal title.
This can be bypassed by specyfing `SET_TERMINAL_TITLE="no"` in the configuration file.
Usage
-----
Use the default `fzf` keys to navigate your notes, e.g., `ctrl-j` and `ctrl-k` for going down/up in the list.
@@ -87,11 +96,16 @@ In addition, there are the following keybindings:
| `alt-up` | Increase task priority |
| `alt-down` | Decrease task priority |
| `ctrl-a` | Open attachments view |
| `ctrl-t` | Filter by category |
| `alt-v` | View bare iCalendar file |
| `alt-0` | Default view: Journal, notes, and _open_ tasks |
| `alt-1` | Display journal entries |
| `alt-2` | Display notes |
| `alt-3` | Display all tasks |
| `alt-j` | Display journal entries |
| `alt-n` | Display notes |
| `alt-t` | Display all tasks |
| `alt-[1-9]` | Display first, second, ... collection |
| `alt-w` | Toggle line-wrap in preview |
| `ctrl-d` | Scroll down in preview |
| `ctrl-u` | Scroll up in preview |
You may also invoke the script with `--help` to see further command-line options.
@@ -99,8 +113,6 @@ In the attachment view, you may use the following keys:
| Key | Action |
| --- | ------ |
| `enter` | Open attachment |
| `j` | Down |
| `k` | Up |
| `w` | Toggle line wrap |
| `ctrl-a` | Add attachment |
| `ctrl-alt-d` | Delete attachment |

BIN
demo/screenshot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 78 KiB

58
scripts/generate_demo.sh Executable file
View File

@@ -0,0 +1,58 @@
#!/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
\`\`\`sh
$(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

@@ -1,24 +0,0 @@
@include "lib/awk/icalendar.awk"
BEGIN { FS = "[:;]"; }
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
/^END:/ && $2 == type { exit }
/^(CATEGORIES|DESCRIPTION|SUMMARY|DUE)/ { prop = $1; c[prop] = $0; next; }
/^[^ ]/ && prop { prop = ""; next; }
/^ / && prop { c[prop] = c[prop] substr($0, 2); next; }
END {
if (!type)
exit
# Process content lines, force CATEGORIES and SUMMARY as single-line
c["CATEGORIES"] = singleline(getcontent(c["CATEGORIES"]))
c["DESCRIPTION"] = getcontent(c["DESCRIPTION"])
c["SUMMARY"] = singleline(getcontent(c["SUMMARY"]))
c["DUE"] = getcontent(c["DUE"])
# Print
if (c["DUE"])
print "::: <| " substr(c["DUE"], 1, 4) "-" substr(c["DUE"], 5, 2) "-" substr(c["DUE"], 7, 2);
print "# " c["SUMMARY"];
print "> " c["CATEGORIES"];
print "";
print c["DESCRIPTION"];
}

View File

@@ -1,14 +1,49 @@
# Retrieve content from iCalendar files
#
# Mandatory variable: `field`.
# Name of field to retrieve.
#
# Optional variable: `format`.
# If `format` is set to "csv", then the content is interpreted as
# comma-separated values, and empty values are dropped.
# If `format` is set to "date", then the content is interpreted as
# a date the output is in the form YYYY-MM-DD.
#
# Optional variable: `oneline`.
# If `oneline` is set, then the all newlines will be replaced by white spaces
@include "lib/awk/icalendar.awk"
# print content of field `field`
BEGIN { FS = ":"; regex = "^" field; }
BEGINFILE { type = ""; line = ""; }
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
/^END:/ && $2 == type { exit }
$0 ~ field { line = $0; next; }
/^END:/ && $2 == type { nextfile }
$0 ~ regex { line = $0; next; }
/^ / && line { line = line substr($0, 2); next; }
/^[^ ]/ && line { exit }
END {
if (!type) { exit }
/^[^ ]/ && line { nextfile }
ENDFILE {
if (type) {
# Process line
print getcontent(line)
content = getcontent(line)
if (oneline)
content = singleline(content)
switch (format) {
case "csv" :
split(content, a, ",")
res = ""
for (i in a) {
if (a[i])
res = res "," a[i]
}
print substr(res, 2)
break
case "date" :
if (content)
print substr(parse_dt("", content), 1, 10)
break
default :
print content
break
}
}
}

View File

@@ -131,6 +131,12 @@ ENDFILE {
# Process content lines
# strings
cat = singleline(unescape(getcontent(c["CATEGORIES"])))
split(cat, a, ",")
cat = ""
for (i in a)
if (a[i])
cat = cat "," a[i]
cat = substr(cat, 2)
sta = singleline(unescape(getcontent(c["STATUS"])))
sum = singleline(unescape(getcontent(c["SUMMARY"])))

View File

@@ -6,23 +6,34 @@ BEGIN {
}
desc { desc = desc "\\n" escape($0); next; }
/^::: \|>/ && !start { gsub("\"", ""); start = substr(zulu, 1, 8); next; }
/^::: <\| / && !due { gsub("\"", ""); due = substr($0, 8); next; }
/^# / && !summary { summary = escape(substr($0, 3)); next; }
/^> / && !categories { categories = escape_but_commas(substr($0, 3)); next; }
/^::: <\|/ && !due { gsub("\"", ""); due = "D" substr($0, 8); next; }
/^# / && !summary { summary = "S" escape(substr($0, 3)); next; }
/^> / && !categories { categories = "C" escape_but_commas(substr($0, 3)); next; }
!$0 && !el { el = 1; next; }
!el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
{ desc = "D" escape($0); next; }
END {
# Sanitize input
type = due ? "VTODO" : "VJOURNAL"
due = substr(due, 2)
summary = substr(summary, 2)
categories = substr(categories, 2)
desc = substr(desc, 2)
if (categories) {
split(categories, a, ",")
categories = ""
for (i in a)
if (a[i])
categories = categories "," a[i]
categories = substr(categories, 2)
}
if (due) {
# Use command line `date` for parsing
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
suc = cmd | getline res
suc = cmd | getline due
close(cmd)
if (suc != 1)
exit 1
due = res ? res : ""
}
# print ical
@@ -52,7 +63,7 @@ END {
}
if (summary) print_fold("SUMMARY:", summary);
if (categories) print_fold("CATEGORIES:", categories);
if (desc) print_fold("DESCRIPTION:", substr(desc, 2));
if (desc) print_fold("DESCRIPTION:", desc);
print "END:" type;
print "END:VCALENDAR"
}

View File

@@ -6,29 +6,43 @@ BEGIN {
}
ENDFILE {
if (NR == FNR && due) {
if (NR == FNR) {
due = substr(due, 2)
summary = substr(summary, 2)
categories = substr(categories, 2)
desc = substr(desc, 2)
if (categories) {
split(categories, a, ",")
categories = ""
for (i in a)
if (a[i])
categories = categories "," a[i]
categories = substr(categories, 2)
}
if (due) {
# Use command line `date` for parsing
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
suc = cmd | getline res
suc = cmd | getline due
close(cmd)
if (suc != 1)
exit 1
due = res ? res : ""
}
}
}
NR == FNR && desc { desc = desc "\\n" escape($0); next; }
NR == FNR && /^::: <\| / && !due { gsub("\"",""); due = substr($0, 8); next; }
NR == FNR && /^# / && !summary { summary = escape(substr($0, 3)); next; }
NR == FNR && /^> / && !categories { categories = escape_but_commas(substr($0, 3)); next; }
NR == FNR && /^::: <\|/ && !due { gsub("\"",""); due = "D" substr($0, 8); next; }
NR == FNR && /^# / && !summary { summary = "S" escape(substr($0, 3)); next; }
NR == FNR && /^> / && !categories { categories = "C" escape_but_commas(substr($0, 3)); next; }
NR == FNR && !$0 && !el { el = 1; next; }
NR == FNR && !el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
NR == FNR { desc = "D" escape($0); next; }
due && type == "VJOURNAL" { print "Notes and journal entries do not have due dates." > "/dev/stderr"; exit 1; }
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2; print; next; }
/^X-ALT-DESC/ && type { next; } # drop this alternative description
/^ / && type { next; } # drop this folded line (the only content with folded lines will be updated)
/^(DUE|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && type { next; } # skip for now, we will write updated fields at the end
/^ / && drop { next; } # drop this folded line
/^X-ALT-DESC/ && type { drop = 1; next; } # drop this alternative description
/^(DUE|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && type { drop = 1; next; } # skip for now, we will write updated fields at the end
{ drop = 0 } # keep everything else
/^SEQUENCE/ && type { seq = $2; next; } # store sequence number and skip
/^END:/ && type == $2 {
seq = seq ? seq + 1 : 1;
@@ -37,7 +51,7 @@ due && type == "VJOURNAL" { print "Notes and journal entries do not have
if (due) print "DUE;VALUE=DATE:" due;
print_fold("SUMMARY:", summary);
print_fold("CATEGORIES:", categories);
print_fold("DESCRIPTION:", substr(desc, 2));
print_fold("DESCRIPTION:", desc);
type = "";
}
{ print }

View File

@@ -104,8 +104,11 @@ function getcontent(str) {
# @local variables: tz
# @input dt_param: iCalendar DTSTART or DTEND parameter string
# @input dt_content: iCalendar DTSTART or DTEND content string
# @return: date or date-time string that can be used in date (1)
function parse_dt(dt_param, dt_content, tz, a, i, k) {
# @return: date or date-time string that can be used in date (1). In
# particular, date strings are of the form YYYY-MM-DD and datetime
# strings are of the form YYYY-MM-DD HH:MM:SS[Z]. If the field
# containts timezone information, then this is prepended.
function parse_dt(dt_param, dt_content, tz, a, i, k, date, time) {
if (dt_param) {
split(dt_param, a, ";")
for (i in a) {
@@ -117,9 +120,9 @@ function parse_dt(dt_param, dt_content, tz, a, i, k) {
}
}
# Get date/date-time
return length(dt_content) == 8 ?
dt dt_content :
dt gensub(/^([0-9]{8})T([0-9]{2})([0-9]{2})([0-9]{2})(Z)?$/, "\\1 \\2:\\3:\\4\\5", "g", dt_content)
date = substr(dt_content, 1, 4) "-" substr(dt_content, 5, 2) "-" substr(dt_content, 7, 2)
time = length(dt_content) == 8 ? "" : " " substr(dt_content, 10, 2) ":" substr(dt_content, 12, 2) ":" substr(dt_content, 14)
return tz date time
}
# Map iCalendar duration specification into the format to be used in date (1).

View File

@@ -2,20 +2,30 @@
set -eu
# Always load functions
# Helper functions
. "sh/helper.sh"
# iCalendar routines
. "sh/icalendar.sh"
# Attachment handling
. "sh/attachment.sh"
# Categories handling
. "sh/categories.sh"
# Read theme
. "sh/theme.sh"
# Load environment variables only when not yet loaded
if [ ! "${SCRIPT_LOADED:-}" ]; then
# Read configuration
. "sh/config.sh"
# Read theme
. "sh/theme.sh"
# Load awk scripts
. "sh/awkscripts.sh"
# Mark as loaded
export SCRIPT_LOADED=1
fi
__lines() {
find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \
find "$ROOT" -mindepth 2 -maxdepth 2 -type f -name '*.ics' -print0 | xargs -0 -P 0 \
awk \
-v collection_labels="$COLLECTION_LABELS" \
-v flag_open="$FLAG_OPEN" \
@@ -35,13 +45,35 @@ __lines() {
# Program starts here
if [ "${1:-}" = "--help" ]; then
bn="$(basename "$0")"
shift
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
echo "Usage: $bn [OPTION] [FILTER]...
[OPTION]
--help Show this help and exit
--new Create new entry and do not 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
--no-... versions, e.g., --no-tasks. Multiple filters are applied in
@@ -51,29 +83,52 @@ if [ "${1:-}" = "--help" ]; then
--tasks Show tasks only
--notes Show notes only
--journal Show jounral only
--journal Show journal only
--completed Show completed tasks only
--open Show open tasks only
--filter <query> Specify custom query"
--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
# iCalendar routines
. "sh/icalendar.sh"
# Command line arguments: Interal use
. "sh/cliinternal.sh"
# Command line arguments: Interal use
# Command line arguments
. "sh/cli.sh"
# Attachment handling
. "sh/attachment.sh"
# Parse command-line filter (if any)
. "sh/filter.sh"
if [ -n "${list_option:-}" ]; then
__lines |
$FZF \
--filter="$query" \
--no-sort \
--with-nth=5.. |
tac
exit 0
fi
# Set terminal title
if [ "$SET_TERMINAL_TITLE" = "yes" ]; then
printf '\033]0;%s\007' "$TERMINAL_TITLE"
fi
while true; do
query=$(stripws "$query")
selection=$(
__lines | $FZF --ansi \
__lines | $FZF \
--ansi \
--query="$query " \
--no-sort \
--no-hscroll \
@@ -81,17 +136,29 @@ while true; do
--print-query \
--accept-nth=4 \
--preview="$0 --preview {4}" \
--expect="ctrl-n,ctrl-alt-d,alt-v,ctrl-a" \
--expect="ctrl-n,ctrl-alt-d,alt-v,ctrl-a,ctrl-t" \
--bind="ctrl-r:reload($0 --reload)" \
--bind="ctrl-x:reload($0 --reload --toggle-completed {4})" \
--bind="alt-up:reload($0 --reload --change-priority '+1' {4})" \
--bind="alt-down:reload($0 --reload --change-priority '-1' {4})" \
--bind="alt-0:change-query(!✅)" \
--bind="alt-1:change-query(📘)" \
--bind="alt-2:change-query(🗒️)" \
--bind="alt-3:change-query(✅ | 🔲)" \
--bind="alt-0:change-query(!$FLAG_COMPLETED )" \
--bind="alt-1:change-query(${COLLECTION1:-} )" \
--bind="alt-2:change-query(${COLLECTION2:-} )" \
--bind="alt-3:change-query(${COLLECTION3:-} )" \
--bind="alt-4:change-query(${COLLECTION4:-} )" \
--bind="alt-5:change-query(${COLLECTION5:-} )" \
--bind="alt-6:change-query(${COLLECTION6:-} )" \
--bind="alt-7:change-query(${COLLECTION7:-} )" \
--bind="alt-8:change-query(${COLLECTION8:-} )" \
--bind="alt-9:change-query(${COLLECTION9:-} )" \
--bind="alt-j:change-query($FLAG_JOURNAL )" \
--bind="alt-n:change-query($FLAG_NOTE )" \
--bind="alt-t:change-query($FLAG_COMPLETED | $FLAG_OPEN )" \
--bind='focus:transform:[ {3} = "VTODO" ] && echo "rebind(ctrl-x)+rebind(alt-up)+rebind(alt-down)" || echo "unbind(ctrl-x)+unbind(alt-up)+unbind(alt-down)"' \
--bind="ctrl-s:execute($SYNC_CMD; [ -n \"${GIT:-}\" ] && ${GIT:-} commit -am 'Synchronized'; printf 'Press <enter> to continue.'; read -r tmp)" ||
--bind="alt-w:toggle-preview-wrap" \
--bind="ctrl-d:preview-half-page-down" \
--bind="ctrl-u:preview-half-page-up" \
--bind="ctrl-s:execute($SYNC_CMD; [ -n \"${GIT:-}\" ] && ${GIT:-echo} add -A && ${GIT:-echo} commit -am 'Synchronized'; printf 'Press <enter> to continue.'; read -r tmp)" ||
true
)
@@ -100,7 +167,7 @@ while true; do
# Line 3: relative file path
lines=$(echo "$selection" | wc -l)
if [ "$lines" -eq 1 ]; then
return 0
exit 0
fi
query=$(echo "$selection" | head -n 1)
key=$(echo "$selection" | head -n 2 | tail -n 1)
@@ -120,6 +187,10 @@ while true; do
"ctrl-a")
__attachment_view "$file"
;;
"ctrl-t")
cat="$(__select_category)"
[ -n "$cat" ] && query="'$cat'"
;;
"")
__edit "$file"
;;

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

@@ -5,13 +5,6 @@ EOF
)
export AWK_ALTERTODO
AWK_EXPORT=$(
cat <<'EOF'
@@include awk/export.awk
EOF
)
export AWK_EXPORT
AWK_GET=$(
cat <<'EOF'
@@include awk/get.awk

19
src/sh/categories.sh Normal file
View File

@@ -0,0 +1,19 @@
# List all categories and lest user select
__select_category() {
find "$ROOT" -type f -name "*.ics" -print0 |
xargs -0 -P 0 \
awk -v field="CATEGORIES" -v format="csv" "$AWK_GET" |
tr ',' '\n' |
sort |
uniq |
grep '.' |
$FZF \
--ansi \
--prompt="Select category> " \
--no-sort \
--tac \
--margin="30%,30%" \
--border=bold \
--border-label="Categories" ||
true
}

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"
"--add-note" | "--add-task" | "--add-jour" | "--collection")
noninteractive=1
;;
"--no-completed")
esac
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
cliquery="${cliquery:-} !$FLAG_COMPLETED"
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
;;
"--open")
*)
due=$(printf "%s" "$1" | tr -dc "[:alnum:][:blank:]")
shift
cliquery="${cliquery:-} $FLAG_OPEN"
if [ -z "$due" ] || ! date -d "$due" >/dev/null 2>&1; then
err "Invalid due date"
exit 1
fi
;;
"--no-open")
shift
cliquery="${cliquery:-} !$FLAG_OPEN"
esac
fi
;;
"--tasks")
"--collection")
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"
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 option \"$1\""
err "Unknown non-interactive option: $1"
exit 1
;;
esac
done
query=${cliquery:-!$FLAG_COMPLETED}
export query
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

@@ -1,4 +1,5 @@
CONFIGFILE="${CONFIGFILE:-$HOME/.config/fzf-vjour/config}"
export TERMINAL_TITLE="🗃️ fzf-vjour | Journal, notes, and tasks"
if [ ! -f "$CONFIGFILE" ]; then
err "Configuration '$CONFIGFILE' not found."
exit 1
@@ -6,17 +7,36 @@ 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:-}"
SET_TERMINAL_TITLE="${SET_TERMINAL_TITLE:-yes}"
export ROOT
export SYNC_CMD
export COLLECTION_LABELS
export SET_TERMINAL_TITLE
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
fi
export "COLLECTION$i=$label"
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
@@ -42,7 +137,16 @@ __edit() {
file="$1"
shift
tmpmd=$(mktemp --suffix='.md')
awk "$AWK_EXPORT" "$file" >"$tmpmd"
due=$(awk -v field="DUE" -v format="date" "$AWK_GET" "$file")
if [ -n "$due" ]; then
echo "::: <| $due" >"$tmpmd"
fi
{
echo "# $(awk -v field="SUMMARY" -v oneline=1 "$AWK_GET" "$file")"
echo "> $(awk -v field="CATEGORIES" -v format="csv" -v oneline=1 "$AWK_GET" "$file")"
echo ""
awk -v field="DESCRIPTION" "$AWK_GET" "$file"
} >>"$tmpmd"
checksum=$(cksum "$tmpmd")
# Open in editor
@@ -100,7 +204,23 @@ __delete() {
# Add file
__new() {
collection=$(printf "%s" "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
collection=$(printf "%s" "$COLLECTION_LABELS" |
tr ';' '\n' |
$FZF \
--ansi \
--prompt="Choose collection> " \
--select-1 \
--no-sort \
--tac \
--margin="30%,30%" \
--delimiter='=' \
--border=bold \
--border-label="Collections" \
--with-nth=2 \
--accept-nth=1 || true)
if [ -z "$collection" ]; then
return
fi
file=""
while [ -f "$file" ] || [ -z "$file" ]; do
uuid=$($UUIDGEN)
@@ -123,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"