Compare commits
20 Commits
31c1357fbb
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 1f15d53c32 | |||
| ded6a686fd | |||
| 7545a4229c | |||
| 93cb0852ea | |||
| 75acdc87f3 | |||
| 56030912d7 | |||
| b2c8d94854 | |||
| c916f46c64 | |||
| cffd89eefd | |||
| 29214c6fe5 | |||
| e0a3905a72 | |||
| 82377a4d5c | |||
| 4027366a63 | |||
| 5f05bc2e0f | |||
| f663c200d2 | |||
| 78d0983464 | |||
| e80d9deb79 | |||
| e1d6b2b08e | |||
| 58680a130d | |||
| 458755b020 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
fzf-vjour
|
fzf-vjour
|
||||||
|
demo/
|
||||||
|
|||||||
23
README.md
23
README.md
@@ -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
|
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/).
|
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.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
@@ -72,6 +78,9 @@ item_types = ["VJOURNAL", "VTODO"]
|
|||||||
|
|
||||||
You may also specify the location of the configuration file with the environment `CONFIGFILE`.
|
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
|
Usage
|
||||||
-----
|
-----
|
||||||
Use the default `fzf` keys to navigate your notes, e.g., `ctrl-j` and `ctrl-k` for going down/up in the list.
|
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-up` | Increase task priority |
|
||||||
| `alt-down` | Decrease task priority |
|
| `alt-down` | Decrease task priority |
|
||||||
| `ctrl-a` | Open attachments view |
|
| `ctrl-a` | Open attachments view |
|
||||||
|
| `ctrl-t` | Filter by category |
|
||||||
| `alt-v` | View bare iCalendar file |
|
| `alt-v` | View bare iCalendar file |
|
||||||
| `alt-0` | Default view: Journal, notes, and _open_ tasks |
|
| `alt-0` | Default view: Journal, notes, and _open_ tasks |
|
||||||
| `alt-1` | Display journal entries |
|
| `alt-j` | Display journal entries |
|
||||||
| `alt-2` | Display notes |
|
| `alt-n` | Display notes |
|
||||||
| `alt-3` | Display all tasks |
|
| `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.
|
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 |
|
| Key | Action |
|
||||||
| --- | ------ |
|
| --- | ------ |
|
||||||
| `enter` | Open attachment |
|
| `enter` | Open attachment |
|
||||||
| `j` | Down |
|
|
||||||
| `k` | Up |
|
|
||||||
| `w` | Toggle line wrap |
|
| `w` | Toggle line wrap |
|
||||||
| `ctrl-a` | Add attachment |
|
| `ctrl-a` | Add attachment |
|
||||||
| `ctrl-alt-d` | Delete attachment |
|
| `ctrl-alt-d` | Delete attachment |
|
||||||
@@ -119,6 +131,7 @@ FLAG_COMPLETED=✅
|
|||||||
FLAG_JOURNAL=📘
|
FLAG_JOURNAL=📘
|
||||||
FLAG_NOTE=🗒️
|
FLAG_NOTE=🗒️
|
||||||
FLAG_PRIORITY=❗
|
FLAG_PRIORITY=❗
|
||||||
|
FLAG_ATTACHMENT=🔗
|
||||||
|
|
||||||
STYLE_COLLECTION="$FAINT$WHITE"
|
STYLE_COLLECTION="$FAINT$WHITE"
|
||||||
STYLE_DATE="$CYAN"
|
STYLE_DATE="$CYAN"
|
||||||
|
|||||||
BIN
demo/screenshot.png
Normal file
BIN
demo/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 78 KiB |
58
scripts/generate_demo.sh
Executable file
58
scripts/generate_demo.sh
Executable 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"
|
||||||
@@ -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"];
|
|
||||||
}
|
|
||||||
@@ -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"
|
@include "lib/awk/icalendar.awk"
|
||||||
|
|
||||||
# print content of field `field`
|
# print content of field `field`
|
||||||
BEGIN { FS = ":"; regex = "^" field; }
|
BEGIN { FS = ":"; regex = "^" field; }
|
||||||
|
BEGINFILE { type = ""; line = ""; }
|
||||||
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
|
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
|
||||||
/^END:/ && $2 == type { exit }
|
/^END:/ && $2 == type { nextfile }
|
||||||
$0 ~ field { line = $0; next; }
|
$0 ~ regex { line = $0; next; }
|
||||||
/^ / && line { line = line substr($0, 2); next; }
|
/^ / && line { line = line substr($0, 2); next; }
|
||||||
/^[^ ]/ && line { exit }
|
/^[^ ]/ && line { nextfile }
|
||||||
END {
|
ENDFILE {
|
||||||
if (!type) { exit }
|
if (type) {
|
||||||
# Process line
|
# 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
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,12 @@ ENDFILE {
|
|||||||
# Process content lines
|
# Process content lines
|
||||||
# strings
|
# strings
|
||||||
cat = singleline(unescape(getcontent(c["CATEGORIES"])))
|
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"])))
|
sta = singleline(unescape(getcontent(c["STATUS"])))
|
||||||
sum = singleline(unescape(getcontent(c["SUMMARY"])))
|
sum = singleline(unescape(getcontent(c["SUMMARY"])))
|
||||||
|
|
||||||
|
|||||||
@@ -2,37 +2,38 @@
|
|||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
FS=":";
|
FS=":";
|
||||||
type = "VJOURNAL";
|
|
||||||
zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1);
|
zulu = strftime("%Y%m%dT%H%M%SZ", systime(), 1);
|
||||||
}
|
}
|
||||||
desc { desc = desc "\\n" escape($0); next; }
|
desc { desc = desc "\\n" escape($0); next; }
|
||||||
{
|
/^::: \|>/ && !start { gsub("\"", ""); start = substr(zulu, 1, 8); next; }
|
||||||
if (substr($0, 1, 6) == "::: |>")
|
/^::: <\|/ && !due { gsub("\"", ""); due = "D" substr($0, 8); next; }
|
||||||
{
|
/^# / && !summary { summary = "S" escape(substr($0, 3)); next; }
|
||||||
start = substr(zulu, 1, 8);
|
/^> / && !categories { categories = "C" escape_but_commas(substr($0, 3)); next; }
|
||||||
getline;
|
!$0 && !el { el = 1; next; }
|
||||||
}
|
!el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
|
||||||
if (substr($0, 1, 6) == "::: <|")
|
{ desc = "D" escape($0); next; }
|
||||||
{
|
|
||||||
type = "VTODO"
|
|
||||||
due = substr($0, 8);
|
|
||||||
getline;
|
|
||||||
}
|
|
||||||
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
|
|
||||||
getline;
|
|
||||||
categories = substr($0, 1, 1) != ">" ? "" : escape_but_commas(substr($0, 3));
|
|
||||||
getline; # This line should be empty
|
|
||||||
getline; # First line of description
|
|
||||||
desc = "D" escape($0);
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
END {
|
END {
|
||||||
# Sanitize input
|
# 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) {
|
if (due) {
|
||||||
# Use command line `date` for parsing
|
# Use command line `date` for parsing
|
||||||
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
|
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
|
||||||
cmd | getline res
|
suc = cmd | getline due
|
||||||
due = res ? res : ""
|
close(cmd)
|
||||||
|
if (suc != 1)
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# print ical
|
# print ical
|
||||||
@@ -62,7 +63,7 @@ END {
|
|||||||
}
|
}
|
||||||
if (summary) print_fold("SUMMARY:", summary);
|
if (summary) print_fold("SUMMARY:", summary);
|
||||||
if (categories) print_fold("CATEGORIES:", categories);
|
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:" type;
|
||||||
print "END:VCALENDAR"
|
print "END:VCALENDAR"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,39 +6,44 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ENDFILE {
|
ENDFILE {
|
||||||
if (NR == FNR)
|
if (NR == FNR) {
|
||||||
{
|
due = substr(due, 2)
|
||||||
# Sanitize input
|
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) {
|
if (due) {
|
||||||
# Use command line `date` for parsing
|
# Use command line `date` for parsing
|
||||||
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
|
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
|
||||||
cmd | getline res
|
suc = cmd | getline due
|
||||||
due = res ? res : ""
|
close(cmd)
|
||||||
|
if (suc != 1)
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NR == FNR && desc { desc = desc "\\n" escape($0); next; }
|
NR == FNR && desc { desc = desc "\\n" escape($0); next; }
|
||||||
NR == FNR {
|
NR == FNR && /^::: <\|/ && !due { gsub("\"",""); due = "D" substr($0, 8); next; }
|
||||||
if (substr($0, 1, 6) == "::: <|")
|
NR == FNR && /^# / && !summary { summary = "S" escape(substr($0, 3)); next; }
|
||||||
{
|
NR == FNR && /^> / && !categories { categories = "C" escape_but_commas(substr($0, 3)); next; }
|
||||||
due = substr($0, 8);
|
NR == FNR && !$0 && !el { el = 1; next; }
|
||||||
getline;
|
NR == FNR && !el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
|
||||||
}
|
NR == FNR { desc = "D" escape($0); next; }
|
||||||
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
|
due && type == "VJOURNAL" { print "Notes and journal entries do not have due dates." > "/dev/stderr"; exit 1; }
|
||||||
getline;
|
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2; print; next; }
|
||||||
categories = substr($0, 1, 1) != ">" ? "" : escape_but_commas(substr($0, 3));
|
/^ / && drop { next; } # drop this folded line
|
||||||
getline; # This line should be empty
|
/^X-ALT-DESC/ && type { drop = 1; next; } # drop this alternative description
|
||||||
getline; # First line of description
|
/^(DUE|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && type { drop = 1; next; } # skip for now, we will write updated fields at the end
|
||||||
desc = "D" escape($0);
|
{ drop = 0 } # keep everything else
|
||||||
next;
|
/^SEQUENCE/ && type { seq = $2; next; } # store sequence number and skip
|
||||||
}
|
|
||||||
|
|
||||||
/^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
|
|
||||||
/^SEQUENCE/ && type { seq = $2; next } # store sequence number and skip
|
|
||||||
/^END:/ && type == $2 {
|
/^END:/ && type == $2 {
|
||||||
seq = seq ? seq + 1 : 1;
|
seq = seq ? seq + 1 : 1;
|
||||||
print "SEQUENCE:" seq;
|
print "SEQUENCE:" seq;
|
||||||
@@ -46,7 +51,7 @@ NR == FNR {
|
|||||||
if (due) print "DUE;VALUE=DATE:" due;
|
if (due) print "DUE;VALUE=DATE:" due;
|
||||||
print_fold("SUMMARY:", summary);
|
print_fold("SUMMARY:", summary);
|
||||||
print_fold("CATEGORIES:", categories);
|
print_fold("CATEGORIES:", categories);
|
||||||
print_fold("DESCRIPTION:", substr(desc, 2));
|
print_fold("DESCRIPTION:", desc);
|
||||||
type = "";
|
type = "";
|
||||||
}
|
}
|
||||||
{ print }
|
{ print }
|
||||||
|
|||||||
@@ -104,8 +104,11 @@ function getcontent(str) {
|
|||||||
# @local variables: tz
|
# @local variables: tz
|
||||||
# @input dt_param: iCalendar DTSTART or DTEND parameter string
|
# @input dt_param: iCalendar DTSTART or DTEND parameter string
|
||||||
# @input dt_content: iCalendar DTSTART or DTEND content string
|
# @input dt_content: iCalendar DTSTART or DTEND content string
|
||||||
# @return: date or date-time string that can be used in date (1)
|
# @return: date or date-time string that can be used in date (1). In
|
||||||
function parse_dt(dt_param, dt_content, tz, a, i, k) {
|
# 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) {
|
if (dt_param) {
|
||||||
split(dt_param, a, ";")
|
split(dt_param, a, ";")
|
||||||
for (i in a) {
|
for (i in a) {
|
||||||
@@ -117,9 +120,9 @@ function parse_dt(dt_param, dt_content, tz, a, i, k) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Get date/date-time
|
# Get date/date-time
|
||||||
return length(dt_content) == 8 ?
|
date = substr(dt_content, 1, 4) "-" substr(dt_content, 5, 2) "-" substr(dt_content, 7, 2)
|
||||||
dt dt_content :
|
time = length(dt_content) == 8 ? "" : " " substr(dt_content, 10, 2) ":" substr(dt_content, 12, 2) ":" substr(dt_content, 14)
|
||||||
dt gensub(/^([0-9]{8})T([0-9]{2})([0-9]{2})([0-9]{2})(Z)?$/, "\\1 \\2:\\3:\\4\\5", "g", dt_content)
|
return tz date time
|
||||||
}
|
}
|
||||||
|
|
||||||
# Map iCalendar duration specification into the format to be used in date (1).
|
# Map iCalendar duration specification into the format to be used in date (1).
|
||||||
|
|||||||
152
src/main.sh
152
src/main.sh
@@ -2,20 +2,30 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
|
# Always load functions
|
||||||
# Helper functions
|
# Helper functions
|
||||||
. "sh/helper.sh"
|
. "sh/helper.sh"
|
||||||
|
# iCalendar routines
|
||||||
|
. "sh/icalendar.sh"
|
||||||
|
# Attachment handling
|
||||||
|
. "sh/attachment.sh"
|
||||||
|
# Categories handling
|
||||||
|
. "sh/categories.sh"
|
||||||
|
|
||||||
# Read theme
|
# Load environment variables only when not yet loaded
|
||||||
. "sh/theme.sh"
|
if [ ! "${SCRIPT_LOADED:-}" ]; then
|
||||||
|
# Read configuration
|
||||||
# Read configuration
|
. "sh/config.sh"
|
||||||
. "sh/config.sh"
|
# Read theme
|
||||||
|
. "sh/theme.sh"
|
||||||
# Load awk scripts
|
# Load awk scripts
|
||||||
. "sh/awkscripts.sh"
|
. "sh/awkscripts.sh"
|
||||||
|
# Mark as loaded
|
||||||
|
export SCRIPT_LOADED=1
|
||||||
|
fi
|
||||||
|
|
||||||
__lines() {
|
__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 \
|
awk \
|
||||||
-v collection_labels="$COLLECTION_LABELS" \
|
-v collection_labels="$COLLECTION_LABELS" \
|
||||||
-v flag_open="$FLAG_OPEN" \
|
-v flag_open="$FLAG_OPEN" \
|
||||||
@@ -35,12 +45,34 @@ __lines() {
|
|||||||
|
|
||||||
# Program starts here
|
# Program starts here
|
||||||
if [ "${1:-}" = "--help" ]; then
|
if [ "${1:-}" = "--help" ]; then
|
||||||
|
bn="$(basename "$0")"
|
||||||
shift
|
shift
|
||||||
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
|
echo "Usage: $bn [OPTION] [FILTER]...
|
||||||
--help Show this help and exit
|
|
||||||
--new Create new entry and do not exit
|
[OPTION]
|
||||||
--git-init Activate git usage and exit
|
--help Show this help and exit
|
||||||
--git <cmd> Run git command 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]
|
[FILTER]
|
||||||
You may specify any of these filters. Filters can be negated using the
|
You may specify any of these filters. Filters can be negated using the
|
||||||
@@ -49,31 +81,54 @@ if [ "${1:-}" = "--help" ]; then
|
|||||||
--no-completed is not the same as --open, and similarly, --no-open is not the
|
--no-completed is not the same as --open, and similarly, --no-open is not the
|
||||||
same as --completed.
|
same as --completed.
|
||||||
|
|
||||||
--tasks Show tasks only
|
--tasks Show tasks only
|
||||||
--notes Show notes only
|
--notes Show notes only
|
||||||
--journal Show jounral only
|
--journal Show journal only
|
||||||
--completed Show completed tasks only
|
--completed Show completed tasks only
|
||||||
--open Show open 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
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# iCalendar routines
|
|
||||||
. "sh/icalendar.sh"
|
|
||||||
|
|
||||||
# Command line arguments: Interal use
|
# Command line arguments: Interal use
|
||||||
. "sh/cliinternal.sh"
|
. "sh/cliinternal.sh"
|
||||||
|
|
||||||
# Command line arguments: Interal use
|
# Command line arguments
|
||||||
. "sh/cli.sh"
|
. "sh/cli.sh"
|
||||||
|
|
||||||
# Attachment handling
|
# Parse command-line filter (if any)
|
||||||
. "sh/attachment.sh"
|
. "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
|
while true; do
|
||||||
query=$(stripws "$query")
|
query=$(stripws "$query")
|
||||||
selection=$(
|
selection=$(
|
||||||
__lines | $FZF --ansi \
|
__lines | $FZF \
|
||||||
|
--ansi \
|
||||||
--query="$query " \
|
--query="$query " \
|
||||||
--no-sort \
|
--no-sort \
|
||||||
--no-hscroll \
|
--no-hscroll \
|
||||||
@@ -81,34 +136,43 @@ while true; do
|
|||||||
--print-query \
|
--print-query \
|
||||||
--accept-nth=4 \
|
--accept-nth=4 \
|
||||||
--preview="$0 --preview {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-r:reload($0 --reload)" \
|
||||||
--bind="ctrl-x:reload($0 --reload --toggle-completed {4})" \
|
--bind="ctrl-x:reload($0 --reload --toggle-completed {4})" \
|
||||||
--bind="alt-up:reload($0 --reload --change-priority '+1' {4})" \
|
--bind="alt-up:reload($0 --reload --change-priority '+1' {4})" \
|
||||||
--bind="alt-down:reload($0 --reload --change-priority '-1' {4})" \
|
--bind="alt-down:reload($0 --reload --change-priority '-1' {4})" \
|
||||||
--bind="alt-0:change-query(!✅)" \
|
--bind="alt-0:change-query(!$FLAG_COMPLETED )" \
|
||||||
--bind="alt-1:change-query(📘)" \
|
--bind="alt-1:change-query(${COLLECTION1:-} )" \
|
||||||
--bind="alt-2:change-query(🗒️)" \
|
--bind="alt-2:change-query(${COLLECTION2:-} )" \
|
||||||
--bind="alt-3:change-query(✅ | 🔲)" \
|
--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='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
|
||||||
)
|
)
|
||||||
|
|
||||||
# Line 1: query
|
# Line 1: query
|
||||||
# Line 2: key ("" for enter)
|
# Line 2: key ("" for enter)
|
||||||
# Line 3: relative file path
|
# Line 3: relative file path
|
||||||
|
lines=$(echo "$selection" | wc -l)
|
||||||
|
if [ "$lines" -eq 1 ]; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
query=$(echo "$selection" | head -n 1)
|
query=$(echo "$selection" | head -n 1)
|
||||||
key=$(echo "$selection" | head -n 2 | tail -n 1)
|
key=$(echo "$selection" | head -n 2 | tail -n 1)
|
||||||
fname=$(echo "$selection" | head -n 3 | tail -n 1)
|
fname=$(echo "$selection" | head -n 3 | tail -n 1)
|
||||||
if [ "$fname" = "$key" ]; then
|
|
||||||
fname=""
|
|
||||||
fi
|
|
||||||
|
|
||||||
file="$ROOT/$fname"
|
file="$ROOT/$fname"
|
||||||
if [ ! -f "$file" ]; then
|
|
||||||
err "File '$file' does not exist!"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$key" in
|
case "$key" in
|
||||||
"ctrl-n")
|
"ctrl-n")
|
||||||
@@ -123,7 +187,11 @@ while true; do
|
|||||||
"ctrl-a")
|
"ctrl-a")
|
||||||
__attachment_view "$file"
|
__attachment_view "$file"
|
||||||
;;
|
;;
|
||||||
*)
|
"ctrl-t")
|
||||||
|
cat="$(__select_category)"
|
||||||
|
[ -n "$cat" ] && query="'$cat'"
|
||||||
|
;;
|
||||||
|
"")
|
||||||
__edit "$file"
|
__edit "$file"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
@@ -5,7 +5,9 @@ __add_attachment() {
|
|||||||
file="$1"
|
file="$1"
|
||||||
shift
|
shift
|
||||||
sel=$(
|
sel=$(
|
||||||
$FZF --prompt="Select attachment> " \
|
$FZF \
|
||||||
|
--ansi \
|
||||||
|
--prompt="Select attachment> " \
|
||||||
--walker="file,hidden" \
|
--walker="file,hidden" \
|
||||||
--walker-root="$HOME" \
|
--walker-root="$HOME" \
|
||||||
--expect="ctrl-c,ctrl-g,ctrl-q,esc"
|
--expect="ctrl-c,ctrl-g,ctrl-q,esc"
|
||||||
@@ -137,6 +139,7 @@ __attachment_view() {
|
|||||||
att=$(
|
att=$(
|
||||||
awk "$AWK_ATTACHLS" "$file" |
|
awk "$AWK_ATTACHLS" "$file" |
|
||||||
$FZF \
|
$FZF \
|
||||||
|
--ansi \
|
||||||
--delimiter="\t" \
|
--delimiter="\t" \
|
||||||
--accept-nth=1,2,3,4 \
|
--accept-nth=1,2,3,4 \
|
||||||
--with-nth="Attachment {1}: \"{2}\" {3} ({5})" \
|
--with-nth="Attachment {1}: \"{2}\" {3} ({5})" \
|
||||||
|
|||||||
@@ -5,13 +5,6 @@ EOF
|
|||||||
)
|
)
|
||||||
export AWK_ALTERTODO
|
export AWK_ALTERTODO
|
||||||
|
|
||||||
AWK_EXPORT=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include awk/export.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_EXPORT
|
|
||||||
|
|
||||||
AWK_GET=$(
|
AWK_GET=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include awk/get.awk
|
@@include awk/get.awk
|
||||||
|
|||||||
19
src/sh/categories.sh
Normal file
19
src/sh/categories.sh
Normal 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
|
||||||
|
}
|
||||||
164
src/sh/cli.sh
164
src/sh/cli.sh
@@ -1,5 +1,5 @@
|
|||||||
# Git
|
case "${1:-}" in
|
||||||
if [ "${1:-}" = "--git-init" ]; then
|
"--git-init")
|
||||||
shift
|
shift
|
||||||
if [ -n "${GIT:-}" ]; then
|
if [ -n "${GIT:-}" ]; then
|
||||||
err "Git already enabled"
|
err "Git already enabled"
|
||||||
@@ -13,9 +13,8 @@ if [ "${1:-}" = "--git-init" ]; then
|
|||||||
git -C "$ROOT" add -A
|
git -C "$ROOT" add -A
|
||||||
git -C "$ROOT" commit -m 'Initial commit: Start git tracking'
|
git -C "$ROOT" commit -m 'Initial commit: Start git tracking'
|
||||||
exit
|
exit
|
||||||
fi
|
;;
|
||||||
|
"--git")
|
||||||
if [ "${1:-}" = "--git" ]; then
|
|
||||||
shift
|
shift
|
||||||
if [ -z "${GIT:-}" ]; then
|
if [ -z "${GIT:-}" ]; then
|
||||||
err "Git not supported, run \`$0 --git-init\` first"
|
err "Git not supported, run \`$0 --git-init\` first"
|
||||||
@@ -23,72 +22,101 @@ if [ "${1:-}" = "--git" ]; then
|
|||||||
fi
|
fi
|
||||||
$GIT "$@"
|
$GIT "$@"
|
||||||
exit
|
exit
|
||||||
fi
|
;;
|
||||||
|
"--new")
|
||||||
# Generate new entry
|
|
||||||
if [ "${1:-}" = "--new" ]; then
|
|
||||||
shift
|
shift
|
||||||
__new
|
__new
|
||||||
fi
|
export next_filter=1
|
||||||
|
;;
|
||||||
|
"--list")
|
||||||
|
shift
|
||||||
|
export next_filter=1
|
||||||
|
export list_option=1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
# Build query
|
if [ -z "${next_filter:-}" ]; then
|
||||||
while [ -n "${1:-}" ]; do
|
# else [FILTER] are the next options
|
||||||
|
# Here, we have --add-xyz with --collection or nothign
|
||||||
case "${1:-}" in
|
case "${1:-}" in
|
||||||
"--completed")
|
"--add-note" | "--add-task" | "--add-jour" | "--collection")
|
||||||
shift
|
noninteractive=1
|
||||||
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
|
esac
|
||||||
done
|
if [ -n "${noninteractive:-}" ]; then
|
||||||
query=${cliquery:-!$FLAG_COMPLETED}
|
while [ -n "${1:-}" ]; do
|
||||||
export query
|
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
|
||||||
|
|||||||
@@ -1,21 +1,42 @@
|
|||||||
CONFIGFILE="${CONFIGFILE:-$HOME/.config/fzf-vjour/config}"
|
CONFIGFILE="${CONFIGFILE:-$HOME/.config/fzf-vjour/config}"
|
||||||
|
export TERMINAL_TITLE="🗃️ fzf-vjour | Journal, notes, and tasks"
|
||||||
if [ ! -f "$CONFIGFILE" ]; then
|
if [ ! -f "$CONFIGFILE" ]; then
|
||||||
err "Configuration '$CONFIGFILE' not found."
|
err "Configuration '$CONFIGFILE' not found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# shellcheck source=/dev/null
|
# shellcheck source=/dev/null
|
||||||
. "$CONFIGFILE"
|
. "$CONFIGFILE"
|
||||||
if [ -z "${ROOT:-}" ] || [ -z "${SYNC_CMD:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
|
if [ -z "${ROOT:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
|
||||||
err "Configuration is incomplete."
|
err "Configuration '$CONFIGFILE' is incomplete."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
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 ROOT
|
||||||
export SYNC_CMD
|
export SYNC_CMD
|
||||||
export COLLECTION_LABELS
|
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
|
# Tools
|
||||||
if command -v "fzf" >/dev/null; then
|
if command -v "fzf" >/dev/null; then
|
||||||
FZF="fzf"
|
FZF="fzf --black"
|
||||||
else
|
else
|
||||||
err "Did not find the command-line fuzzy finder fzf."
|
err "Did not find the command-line fuzzy finder fzf."
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
61
src/sh/filter.sh
Normal file
61
src/sh/filter.sh
Normal 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
|
||||||
@@ -1,5 +1,100 @@
|
|||||||
# Interface to modify iCalendar files
|
# 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
|
# Toggle completed status of VTODO
|
||||||
#
|
#
|
||||||
# @input $1: Relative path to iCalendar file
|
# @input $1: Relative path to iCalendar file
|
||||||
@@ -41,24 +136,41 @@ __change_priority() {
|
|||||||
__edit() {
|
__edit() {
|
||||||
file="$1"
|
file="$1"
|
||||||
shift
|
shift
|
||||||
filetmp=$(mktemp --suffix='.md')
|
tmpmd=$(mktemp --suffix='.md')
|
||||||
awk "$AWK_EXPORT" "$file" >"$filetmp"
|
due=$(awk -v field="DUE" -v format="date" "$AWK_GET" "$file")
|
||||||
checksum=$(cksum "$filetmp")
|
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
|
# Open in editor
|
||||||
$EDITOR "$filetmp" >/dev/tty
|
$EDITOR "$tmpmd" >/dev/tty
|
||||||
|
|
||||||
# Update only if changes are detected
|
# Update only if changes are detected
|
||||||
if [ "$checksum" != "$(cksum "$filetmp")" ]; then
|
while [ "$checksum" != "$(cksum "$tmpmd")" ]; do
|
||||||
file_new="$filetmp.ics"
|
tmpfile="$tmpmd.ics"
|
||||||
awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
|
if awk "$AWK_UPDATE" "$tmpmd" "$file" >"$tmpfile"; then
|
||||||
mv "$file_new" "$file"
|
mv "$tmpfile" "$file"
|
||||||
if [ -n "${GIT:-}" ]; then
|
if [ -n "${GIT:-}" ]; then
|
||||||
$GIT add "$file"
|
$GIT add "$file"
|
||||||
$GIT commit -q -m "File modified" -- "$file"
|
$GIT commit -q -m "File modified" -- "$file"
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
else
|
||||||
|
rm -f "$tmpfile"
|
||||||
|
err "Failed to update entry. Press <enter> to continue."
|
||||||
|
read -r tmp
|
||||||
|
# Re-open in editor
|
||||||
|
$EDITOR "$tmpmd" >/dev/tty
|
||||||
fi
|
fi
|
||||||
fi
|
done
|
||||||
rm "$filetmp"
|
rm "$tmpmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Delete file
|
# Delete file
|
||||||
@@ -92,7 +204,23 @@ __delete() {
|
|||||||
|
|
||||||
# Add file
|
# Add file
|
||||||
__new() {
|
__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=""
|
file=""
|
||||||
while [ -f "$file" ] || [ -z "$file" ]; do
|
while [ -f "$file" ] || [ -z "$file" ]; do
|
||||||
uuid=$($UUIDGEN)
|
uuid=$($UUIDGEN)
|
||||||
@@ -112,14 +240,25 @@ __new() {
|
|||||||
$EDITOR "$tmpmd" >/dev/tty
|
$EDITOR "$tmpmd" >/dev/tty
|
||||||
|
|
||||||
# Update if changes are detected
|
# Update if changes are detected
|
||||||
if [ "$checksum" != "$(cksum "$tmpmd")" ]; then
|
while [ "$checksum" != "$(cksum "$tmpmd")" ]; do
|
||||||
tmpfile="$tmpmd.ics"
|
tmpfile="$tmpmd.ics"
|
||||||
awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"
|
if awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"; then
|
||||||
mv "$tmpfile" "$file"
|
if [ ! -d "$ROOT/$collection" ]; then
|
||||||
if [ -n "${GIT:-}" ]; then
|
mkdir -p "$ROOT/$collection"
|
||||||
$GIT add "$file"
|
fi
|
||||||
$GIT commit -q -m "File added" -- "$file"
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "File added" -- "$file"
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
else
|
||||||
|
rm -f "$tmpfile"
|
||||||
|
err "Failed to create new entry. Press <enter> to continue."
|
||||||
|
read -r tmp
|
||||||
|
# Re-open in editor
|
||||||
|
$EDITOR "$tmpmd" >/dev/tty
|
||||||
fi
|
fi
|
||||||
fi
|
done
|
||||||
rm "$tmpmd"
|
rm "$tmpmd"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user