Compare commits
17 Commits
dev
...
bc0233962a
| Author | SHA1 | Date | |
|---|---|---|---|
| bc0233962a | |||
| c8f88b2410 | |||
| a9bdca55b5 | |||
| 0dd0a81a64 | |||
| 53149ea9db | |||
| c63b3c4ee2 | |||
| d228f551ab | |||
| 3fe908738f | |||
| 8f04082d65 | |||
| 7f04d84b30 | |||
| 3150e877c7 | |||
| 26a6900555 | |||
| 76fa32da39 | |||
| 609d9712a6 | |||
| de4650d1ac | |||
| 7656da2a71 | |||
| 6c78213587 |
22
README.md
22
README.md
@@ -13,14 +13,22 @@ with a CalDav server, such as [Radicale](https://radicale.org/), and a synchroni
|
|||||||
|
|
||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
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.
|
### Manual
|
||||||
|
|
||||||
|
Run `./scripts/build.sh`, then copy `fzf-vjour` to your preferred location, e.g., `~/.local/bin`, and make it executable.
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
This is a POSIX script with inline `awk` elements.
|
This is a POSIX script with inline `awk` elements.
|
||||||
Make sure you have [fzf](https://github.com/junegunn/fzf) installed.
|
Make sure you have [fzf](https://github.com/junegunn/fzf) installed.
|
||||||
I also suggest to install [batcat](https://github.com/sharkdp/bat) for colorful previews.
|
I also suggest to install [batcat](https://github.com/sharkdp/bat) for colorful previews.
|
||||||
|
|
||||||
|
### Arch Linux
|
||||||
|
|
||||||
|
```bash
|
||||||
|
yay -S fzf-vjour-git
|
||||||
|
```
|
||||||
|
|
||||||
Configuration
|
Configuration
|
||||||
--------------
|
--------------
|
||||||
This application is configured with a file located at `$HOME/.config/fzf-vjour/config`.
|
This application is configured with a file located at `$HOME/.config/fzf-vjour/config`.
|
||||||
@@ -83,6 +91,16 @@ In addition, there are the following keybindings:
|
|||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
Limitations
|
||||||
|
-----------
|
||||||
|
Here is a list of some currently present limitations.
|
||||||
|
|
||||||
|
- Timezone agnostic: Timezone specifications are ignored.
|
||||||
|
- Time agnostic: We use the date portion only of date-time specifications.
|
||||||
|
- No alarms or notifications
|
||||||
|
- No attachments
|
||||||
|
- No recurrences
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
This project is licensed under the [MIT License](./LICENSE).
|
This project is licensed under the [MIT License](./LICENSE).
|
||||||
|
|||||||
@@ -5,7 +5,15 @@ GREEN="\033[0;32m"
|
|||||||
OFF="\033[m"
|
OFF="\033[m"
|
||||||
NAME="fzf-vjour"
|
NAME="fzf-vjour"
|
||||||
SRC="./src/main.sh"
|
SRC="./src/main.sh"
|
||||||
echo "🐔 ${GREEN}Building${OFF} ${BOLD}$NAME${OFF}"
|
|
||||||
sed -E 's|@@include (.+)$|cat \1|e' "$SRC" >"$NAME"
|
tmpdir=$(mktemp -d)
|
||||||
|
echo "🐔 ${GREEN}Internalize sourced files${OFF}"
|
||||||
|
sed -E 's|\. "([^$].+)"$|cat src/\1|e' "$SRC" >"$tmpdir/1.sh"
|
||||||
|
echo "🥚 ${GREEN}Internalize awk scripts${OFF}"
|
||||||
|
sed -E 's|@@include (.+)$|cat src/\1|e' "$tmpdir/1.sh" >"$tmpdir/2.sh"
|
||||||
|
echo "🐔 ${GREEN}Internalize awk libraries${OFF}"
|
||||||
|
sed -E 's|@include "(.+)"$|cat src/\1|e' "$tmpdir/2.sh" >"$NAME"
|
||||||
|
echo "🥚 ${GREEN}Make executable and cleanup${OFF}"
|
||||||
chmod +x "$NAME"
|
chmod +x "$NAME"
|
||||||
echo "🥚 ${GREEN}Done${OFF}"
|
rm -rf "$tmpdir"
|
||||||
|
echo "🍳 ${GREEN}Done:${OFF} Sucessfully built ${BOLD}${GREEN}$NAME${OFF}"
|
||||||
|
|||||||
@@ -1,34 +1,19 @@
|
|||||||
function getcontent(content_line, prop)
|
@include "lib/awk/icalendar.awk"
|
||||||
{
|
|
||||||
return substr(content_line[prop], index(content_line[prop], ":") + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function storetext_line(content_line, c, prop)
|
|
||||||
{
|
|
||||||
c[prop] = getcontent(content_line, prop);
|
|
||||||
gsub("\\\\n", "\n", c[prop]);
|
|
||||||
gsub("\\\\N", "\n", c[prop]);
|
|
||||||
gsub("\\\\,", ",", c[prop]);
|
|
||||||
gsub("\\\\;", ";", c[prop]);
|
|
||||||
gsub("\\\\\\\\", "\\", c[prop]);
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN { FS = "[:;]"; }
|
|
||||||
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
|
|
||||||
/^END:/ && $2 == type { exit }
|
|
||||||
/^(CATEGORIES|DESCRIPTION|SUMMARY|DUE)/ { prop = $1; content_line[prop] = $0; next; }
|
|
||||||
/^[^ ]/ && prop { prop = ""; next; }
|
|
||||||
/^ / && prop { content_line[prop] = content_line[prop] substr($0, 2); next; }
|
|
||||||
|
|
||||||
|
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 {
|
END {
|
||||||
if (!type) {
|
if (!type)
|
||||||
exit
|
exit
|
||||||
}
|
# Process content lines, force CATEGORIES and SUMMARY as single-line
|
||||||
# Process content lines
|
c["CATEGORIES"] = singleline(getcontent(c["CATEGORIES"]))
|
||||||
storetext_line(content_line, c, "CATEGORIES" );
|
c["DESCRIPTION"] = getcontent(c["DESCRIPTION"])
|
||||||
storetext_line(content_line, c, "DESCRIPTION");
|
c["SUMMARY"] = singleline(getcontent(c["SUMMARY"]))
|
||||||
storetext_line(content_line, c, "SUMMARY" );
|
c["DUE"] = getcontent(c["DUE"])
|
||||||
storetext_line(content_line, c, "DUE" );
|
|
||||||
# Print
|
# Print
|
||||||
if (c["DUE"])
|
if (c["DUE"])
|
||||||
print "::: <| " substr(c["DUE"], 1, 4) "-" substr(c["DUE"], 5, 2) "-" substr(c["DUE"], 7, 2);
|
print "::: <| " substr(c["DUE"], 1, 4) "-" substr(c["DUE"], 5, 2) "-" substr(c["DUE"], 7, 2);
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
|
@include "lib/awk/icalendar.awk"
|
||||||
|
|
||||||
# print content of field `field`
|
# print content of field `field`
|
||||||
BEGIN { FS = ":"; regex = "^" field; }
|
BEGIN { FS = ":"; regex = "^" field; }
|
||||||
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
|
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
|
||||||
/^END:/ && $2 == type { exit }
|
/^END:/ && $2 == type { exit }
|
||||||
$0 ~ field { content = $0; next; }
|
$0 ~ field { line = $0; next; }
|
||||||
/^ / && content { content = content substr($0, 2); next; }
|
/^ / && line { line = line substr($0, 2); next; }
|
||||||
/^[^ ]/ && content { exit }
|
/^[^ ]/ && line { exit }
|
||||||
END {
|
END {
|
||||||
if (!type) { exit }
|
if (!type) { exit }
|
||||||
# Process content line
|
# Process line
|
||||||
content = substr(content, index(content, ":") + 1);
|
print getcontent(line)
|
||||||
gsub("\\\\n", "\n", content);
|
|
||||||
gsub("\\\\N", "\n", content);
|
|
||||||
gsub("\\\\,", ",", content);
|
|
||||||
gsub("\\\\;", ";", content);
|
|
||||||
gsub("\\\\\\\\", "\\", content);
|
|
||||||
print content;
|
|
||||||
}
|
}
|
||||||
|
|||||||
113
src/awk/list.awk
113
src/awk/list.awk
@@ -3,39 +3,15 @@
|
|||||||
# See https://datatracker.ietf.org/doc/html/rfc5545 for the RFC 5545 that
|
# See https://datatracker.ietf.org/doc/html/rfc5545 for the RFC 5545 that
|
||||||
# describes iCalendar, and its syntax
|
# describes iCalendar, and its syntax
|
||||||
|
|
||||||
function getcontent(content_line, prop)
|
@include "lib/awk/icalendar.awk"
|
||||||
{
|
|
||||||
return substr(content_line[prop], index(content_line[prop], ":") + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function storetext_line(content_line, c, prop)
|
# Generate kind-of-pretty date strings.
|
||||||
{
|
#
|
||||||
c[prop] = getcontent(content_line, prop);
|
# @local variables: ts, ts_y, ts_m, ts_d, delta
|
||||||
gsub("\\\\n", " ", c[prop]);
|
# @input date: Date in the format YYYYMMDD
|
||||||
gsub("\\\\N", " ", c[prop]);
|
# @input todaystamp: Today, seconds since epoch
|
||||||
gsub("\\\\,", ",", c[prop]);
|
# @return: string
|
||||||
gsub("\\\\;", ";", c[prop]);
|
function formatdate(date, todaystamp, ts, ts_y, ts_m, ts_d, delta)
|
||||||
gsub("\\\\\\\\", "\\", c[prop]);
|
|
||||||
#gsub(" ", "_", c[prop]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function storeinteger(content_line, c, prop)
|
|
||||||
{
|
|
||||||
c[prop] = getcontent(content_line, prop);
|
|
||||||
c[prop] = c[prop] ? c[prop] : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function storedatetime(content_line, c, prop)
|
|
||||||
{
|
|
||||||
c[prop] = getcontent(content_line, prop);
|
|
||||||
}
|
|
||||||
|
|
||||||
function storedate(content_line, c, prop)
|
|
||||||
{
|
|
||||||
c[prop] = substr(getcontent(content_line, prop), 1, 8);
|
|
||||||
}
|
|
||||||
|
|
||||||
function formatdate(date, today, todaystamp, ts, ts_y, ts_m, ts_d, delta)
|
|
||||||
{
|
{
|
||||||
ts_y = substr(date, 1, 4);
|
ts_y = substr(date, 1, 4);
|
||||||
ts_m = substr(date, 5, 2);
|
ts_m = substr(date, 5, 2);
|
||||||
@@ -87,7 +63,6 @@ BEGIN {
|
|||||||
RED = "\033[1;31m";
|
RED = "\033[1;31m";
|
||||||
WHITE = "\033[1;97m";
|
WHITE = "\033[1;97m";
|
||||||
CYAN = "\033[1;36m";
|
CYAN = "\033[1;36m";
|
||||||
FAINT = "\033[2m";
|
|
||||||
OFF = "\033[m";
|
OFF = "\033[m";
|
||||||
|
|
||||||
# For date comparision
|
# For date comparision
|
||||||
@@ -99,9 +74,7 @@ BEGIN {
|
|||||||
BEGINFILE {
|
BEGINFILE {
|
||||||
type = "";
|
type = "";
|
||||||
prop = "";
|
prop = "";
|
||||||
delete content_line;
|
|
||||||
delete c;
|
delete c;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/^BEGIN:(VJOURNAL|VTODO)/ {
|
/^BEGIN:(VJOURNAL|VTODO)/ {
|
||||||
@@ -112,9 +85,9 @@ BEGINFILE {
|
|||||||
nextfile
|
nextfile
|
||||||
}
|
}
|
||||||
|
|
||||||
/^(CATEGORIES|DESCRIPTION|PRIORITY|STATUS|SUMMARY|COMPLETED|DUE|DTSTART|DURATION|CREATED|DTSTAMP|LAST-MODIFIED)/ {
|
/^(CATEGORIES|PRIORITY|STATUS|SUMMARY|COMPLETED|DUE|DTSTART|DURATION|CREATED|DTSTAMP|LAST-MODIFIED)/ {
|
||||||
prop = $1;
|
prop = $1;
|
||||||
content_line[prop] = $0;
|
c[prop] = $0;
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
/^[^ ]/ && prop {
|
/^[^ ]/ && prop {
|
||||||
@@ -122,7 +95,7 @@ BEGINFILE {
|
|||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
/^ / && prop {
|
/^ / && prop {
|
||||||
content_line[prop] = content_line[prop] substr($0, 2);
|
c[prop] = c[prop] substr($0, 2);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,6 +110,7 @@ ENDFILE {
|
|||||||
{
|
{
|
||||||
print 10,
|
print 10,
|
||||||
"-",
|
"-",
|
||||||
|
type,
|
||||||
"-",
|
"-",
|
||||||
RED "ERROR: file '" fpath "' contains whitespaces!" OFF
|
RED "ERROR: file '" fpath "' contains whitespaces!" OFF
|
||||||
exit
|
exit
|
||||||
@@ -146,26 +120,33 @@ ENDFILE {
|
|||||||
collection = collection in collection2label ? collection2label[collection] : collection;
|
collection = collection in collection2label ? collection2label[collection] : collection;
|
||||||
|
|
||||||
# Process content lines
|
# Process content lines
|
||||||
storetext_line(content_line, c, "CATEGORIES" );
|
# strings
|
||||||
storetext_line(content_line, c, "DESCRIPTION" );
|
cat = singleline(unescape(getcontent(c["CATEGORIES"])))
|
||||||
storeinteger( content_line, c, "PRIORITY" );
|
sta = singleline(unescape(getcontent(c["STATUS"])))
|
||||||
storetext_line(content_line, c, "STATUS" );
|
sum = singleline(unescape(getcontent(c["SUMMARY"])))
|
||||||
storetext_line(content_line, c, "SUMMARY" );
|
|
||||||
storedatetime( content_line, c, "COMPLETED" );
|
# integers
|
||||||
storedate( content_line, c, "DUE" );
|
pri = unescape(getcontent(c["PRIORITY"]))
|
||||||
storedate( content_line, c, "DTSTART" );
|
pri = pri ? pri + 0 : 0
|
||||||
storedatetime( content_line, c, "DURATION" );
|
|
||||||
storedatetime( content_line, c, "CREATED" );
|
# dates
|
||||||
storedatetime( content_line, c, "DTSTAMP" );
|
due = substr(unescape(getcontent(c["DUE"])), 1, 8)
|
||||||
storedatetime( content_line, c, "LAST-MODIFIED");
|
dts = substr(unescape(getcontent(c["DTSTART"])), 1, 8)
|
||||||
|
|
||||||
|
# date-times
|
||||||
|
com = unescape(getcontent(c["COMPLETED"]))
|
||||||
|
dur = unescape(getcontent(c["DURATION"]))
|
||||||
|
cre = unescape(getcontent(c["CREATED"]))
|
||||||
|
stp = unescape(getcontent(c["DTSTAMP"]))
|
||||||
|
lmd = unescape(getcontent(c["LAST-MODIFIED"]))
|
||||||
|
|
||||||
# Priority field, primarly used for sorting
|
# Priority field, primarly used for sorting
|
||||||
priotext = "";
|
psort = 0;
|
||||||
prio = 0;
|
priotext = ""
|
||||||
if (c["PRIORITY"] > 0)
|
if (pri > 0)
|
||||||
{
|
{
|
||||||
priotext = "❗(" c["PRIORITY"] ") ";
|
priotext = "❗(" pri ") "
|
||||||
prio = 10 - c["PRIORITY"];
|
psort = 10 - pri
|
||||||
}
|
}
|
||||||
|
|
||||||
# Last modification/creation time stamp, used for sorting
|
# Last modification/creation time stamp, used for sorting
|
||||||
@@ -173,7 +154,7 @@ ENDFILE {
|
|||||||
# UTC time format
|
# UTC time format
|
||||||
# DTSTAMP: mandatory field in VTODO and VJOURNAL, date-time in UTC time
|
# DTSTAMP: mandatory field in VTODO and VJOURNAL, date-time in UTC time
|
||||||
# format
|
# format
|
||||||
mod = c["LAST-MODIFIED"] ? c["LAST-MODIFIED"] : c["DTSTAMP"];
|
mod = lmd ? lmd : stp
|
||||||
|
|
||||||
# Date field. For VTODO entries, we show the due date, for journal entries,
|
# Date field. For VTODO entries, we show the due date, for journal entries,
|
||||||
# the associated date.
|
# the associated date.
|
||||||
@@ -183,39 +164,39 @@ ENDFILE {
|
|||||||
if (type == "VTODO")
|
if (type == "VTODO")
|
||||||
{
|
{
|
||||||
# Either DUE or DURATION may appear. If DURATION appears, then also DTSTART
|
# Either DUE or DURATION may appear. If DURATION appears, then also DTSTART
|
||||||
d = c["DUE"] ? c["DUE"] :
|
d = due ? due : (dur ? dts " for " dur : "");
|
||||||
(c["DURATION"] ? c["DTSTART"] " for " c["DURATION"] : "");
|
if (d && d <= today && sta != "COMPLETED")
|
||||||
if (d && d <= today && c["STATUS"] != "COMPLETED")
|
|
||||||
{
|
{
|
||||||
datecolor = RED;
|
datecolor = RED;
|
||||||
summarycolor = RED;
|
summarycolor = RED;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
d = c["DTSTART"];
|
d = dts
|
||||||
}
|
}
|
||||||
d = d ? formatdate(d, today, todaystamp ts, ts_y, ts_m, ts_d, delta) : " ";
|
d = d ? formatdate(d, todaystamp) : " ";
|
||||||
|
|
||||||
# flag: - "journal" for VJOURNAL with DTSTART
|
# flag: - "journal" for VJOURNAL with DTSTART
|
||||||
# - "note" for VJOURNAL without DTSTART
|
# - "note" for VJOURNAL without DTSTART
|
||||||
# - "completed" for VTODO with c["STATUS"] == COMPLETED
|
# - "completed" for VTODO with c["STATUS"] == COMPLETED
|
||||||
# - "open" for VTODO with c["STATUS"] != COMPLETED
|
# - "open" for VTODO with c["STATUS"] != COMPLETED
|
||||||
if (type == "VTODO")
|
if (type == "VTODO")
|
||||||
flag = c["STATUS"] == "COMPLETED" ? flag_completed : flag_open;
|
flag = sta == "COMPLETED" ? flag_completed : flag_open;
|
||||||
else
|
else
|
||||||
flag = c["DTSTART"] ? flag_journal : flag_note;
|
flag = dts ? flag_journal : flag_note;
|
||||||
|
|
||||||
# summary
|
# summary
|
||||||
# c["SUMMARY"]
|
# c["SUMMARY"]
|
||||||
summary = c["SUMMARY"] ? c["SUMMARY"] : " "
|
summary = sum ? sum : " "
|
||||||
|
|
||||||
# categories
|
# categories
|
||||||
categories = c["CATEGORIES"] ? c["CATEGORIES"] : " "
|
categories = cat ? cat : " "
|
||||||
|
|
||||||
# filename
|
# filename
|
||||||
# FILENAME
|
# FILENAME
|
||||||
|
|
||||||
print prio,
|
print psort,
|
||||||
mod,
|
mod,
|
||||||
|
type,
|
||||||
fpath,
|
fpath,
|
||||||
collection,
|
collection,
|
||||||
datecolor d OFF,
|
datecolor d OFF,
|
||||||
|
|||||||
@@ -1,36 +1,11 @@
|
|||||||
function escape_categories(str)
|
@include "lib/awk/icalendar.awk"
|
||||||
{
|
|
||||||
gsub("\\\\", "\\\\", str);
|
|
||||||
gsub(";", "\\\\;", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function escape(str)
|
|
||||||
{
|
|
||||||
escape_categories(str)
|
|
||||||
gsub(",", "\\\\,", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function print_fold(nameparam, content, i, s)
|
|
||||||
{
|
|
||||||
i = 74 - length(nameparam);
|
|
||||||
s = substr(content, 1, i);
|
|
||||||
print nameparam s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
while (s)
|
|
||||||
{
|
|
||||||
print " " s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
FS=":";
|
FS=":";
|
||||||
type = "VJOURNAL";
|
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" $0; next; }
|
desc { desc = desc "\\n" escape($0); next; }
|
||||||
{
|
{
|
||||||
if (substr($0, 1, 6) == "::: |>")
|
if (substr($0, 1, 6) == "::: |>")
|
||||||
{
|
{
|
||||||
@@ -43,12 +18,12 @@ desc { desc = desc "\\n" $0; next; }
|
|||||||
due = substr($0, 8);
|
due = substr($0, 8);
|
||||||
getline;
|
getline;
|
||||||
}
|
}
|
||||||
summary = substr($0, 1, 2) != "# " ? "" : substr($0, 3);
|
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
|
||||||
getline;
|
getline;
|
||||||
categories = substr($0, 1, 1) != ">" ? "" : substr($0, 3);
|
categories = substr($0, 1, 1) != ">" ? "" : escape_but_commas(substr($0, 3));
|
||||||
getline; # This line should be empty
|
getline; # This line should be empty
|
||||||
getline; # First line of description
|
getline; # First line of description
|
||||||
desc = $0;
|
desc = "D" escape($0);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
END {
|
END {
|
||||||
@@ -59,15 +34,12 @@ END {
|
|||||||
cmd | getline res
|
cmd | getline res
|
||||||
due = res ? res : ""
|
due = res ? res : ""
|
||||||
}
|
}
|
||||||
escape(summary);
|
|
||||||
escape(desc);
|
|
||||||
escape_categories(categories);
|
|
||||||
|
|
||||||
# print ical
|
# print ical
|
||||||
print "BEGIN:VCALENDAR";
|
print "BEGIN:VCALENDAR";
|
||||||
print "VERSION:2.0";
|
print "VERSION:2.0";
|
||||||
print "CALSCALE:GREGORIAN";
|
print "CALSCALE:GREGORIAN";
|
||||||
print "PRODID:-//fab//awk//EN";
|
print "PRODID:-//fzf-vjour//awk//EN";
|
||||||
print "BEGIN:" type;
|
print "BEGIN:" type;
|
||||||
print "DTSTAMP:" zulu;
|
print "DTSTAMP:" zulu;
|
||||||
print "UID:" uid;
|
print "UID:" uid;
|
||||||
@@ -88,9 +60,9 @@ END {
|
|||||||
if (start)
|
if (start)
|
||||||
print "DTSTART;VALUE=DATE:" start;
|
print "DTSTART;VALUE=DATE:" start;
|
||||||
}
|
}
|
||||||
if (summary) print_fold("SUMMARY:", summary, i, s);
|
if (summary) print_fold("SUMMARY:", summary);
|
||||||
if (categories) print_fold("CATEGORIES:", categories, i, s);
|
if (categories) print_fold("CATEGORIES:", categories);
|
||||||
if (desc) print_fold("DESCRIPTION:", desc, i, s);
|
if (desc) print_fold("DESCRIPTION:", substr(desc, 2));
|
||||||
print "END:" type;
|
print "END:" type;
|
||||||
print "END:VCALENDAR"
|
print "END:VCALENDAR"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,34 +1,4 @@
|
|||||||
function getcontent(content_line, prop)
|
@include "lib/awk/icalendar.awk"
|
||||||
{
|
|
||||||
return substr(content_line[prop], index(content_line[prop], ":") + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
function escape_categories(str)
|
|
||||||
{
|
|
||||||
gsub("\\\\", "\\\\", str);
|
|
||||||
gsub(";", "\\\\;", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function escape(str)
|
|
||||||
{
|
|
||||||
escape_categories(str)
|
|
||||||
gsub(",", "\\\\,", str);
|
|
||||||
}
|
|
||||||
|
|
||||||
function print_fold(nameparam, content, i, s)
|
|
||||||
{
|
|
||||||
i = 74 - length(nameparam);
|
|
||||||
s = substr(content, 1, i);
|
|
||||||
print nameparam s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
while (s)
|
|
||||||
{
|
|
||||||
print " " s;
|
|
||||||
s = substr(content, i+1, 73);
|
|
||||||
i = i + 73;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
BEGIN {
|
BEGIN {
|
||||||
FS=":";
|
FS=":";
|
||||||
@@ -45,25 +15,22 @@ ENDFILE {
|
|||||||
cmd | getline res
|
cmd | getline res
|
||||||
due = res ? res : ""
|
due = res ? res : ""
|
||||||
}
|
}
|
||||||
escape(summary);
|
|
||||||
escape(desc);
|
|
||||||
escape_categories(categories);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NR == FNR && desc { desc = desc "\\n" $0; next; }
|
NR == FNR && desc { desc = desc "\\n" escape($0); next; }
|
||||||
NR == FNR {
|
NR == FNR {
|
||||||
if (substr($0, 1, 6) == "::: <|")
|
if (substr($0, 1, 6) == "::: <|")
|
||||||
{
|
{
|
||||||
due = substr($0, 8);
|
due = substr($0, 8);
|
||||||
getline;
|
getline;
|
||||||
}
|
}
|
||||||
summary = substr($0, 1, 2) != "# " ? "" : substr($0, 3);
|
summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
|
||||||
getline;
|
getline;
|
||||||
categories = substr($0, 1, 1) != ">" ? "" : substr($0, 3);
|
categories = substr($0, 1, 1) != ">" ? "" : escape_but_commas(substr($0, 3));
|
||||||
getline; # This line should be empty
|
getline; # This line should be empty
|
||||||
getline; # First line of description
|
getline; # First line of description
|
||||||
desc = $0;
|
desc = "D" escape($0);
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -77,9 +44,9 @@ NR == FNR {
|
|||||||
print "SEQUENCE:" seq;
|
print "SEQUENCE:" seq;
|
||||||
print "LAST-MODIFIED:" zulu;
|
print "LAST-MODIFIED:" zulu;
|
||||||
if (due) print "DUE;VALUE=DATE:" due;
|
if (due) print "DUE;VALUE=DATE:" due;
|
||||||
print_fold("SUMMARY:", summary, i, s);
|
print_fold("SUMMARY:", summary);
|
||||||
print_fold("CATEGORIES:", categories, i, s);
|
print_fold("CATEGORIES:", categories);
|
||||||
print_fold("DESCRIPTION:", desc, i, s);
|
print_fold("DESCRIPTION:", substr(desc, 2));
|
||||||
type = "";
|
type = "";
|
||||||
}
|
}
|
||||||
{ print }
|
{ print }
|
||||||
|
|||||||
143
src/lib/awk/icalendar.awk
Normal file
143
src/lib/awk/icalendar.awk
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
# Make string single-line
|
||||||
|
#
|
||||||
|
# @input str: String
|
||||||
|
# @return: String without newlines
|
||||||
|
function singleline(str) {
|
||||||
|
gsub("\\n", " ", str)
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
# Escape string to be used as content in iCalendar files.
|
||||||
|
#
|
||||||
|
# @input str: String to escape
|
||||||
|
# @return: Escaped string
|
||||||
|
function escape(str)
|
||||||
|
{
|
||||||
|
gsub("\\\\", "\\\\", str)
|
||||||
|
gsub("\\n", "\\n", str)
|
||||||
|
gsub(";", "\\;", str)
|
||||||
|
gsub(",", "\\,", str)
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
# Escape string to be used as content in iCalendar files, but don't escape
|
||||||
|
# commas.
|
||||||
|
#
|
||||||
|
# @input str: String to escape
|
||||||
|
# @return: Escaped string
|
||||||
|
function escape_but_commas(str)
|
||||||
|
{
|
||||||
|
gsub("\\\\", "\\\\", str)
|
||||||
|
gsub("\\n", "\\n", str)
|
||||||
|
gsub(";", "\\;", str)
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
# Print property with its content and fold according to the iCalendar
|
||||||
|
# specification.
|
||||||
|
#
|
||||||
|
# @local variables: i, s
|
||||||
|
# @input nameparam: Property name with optional parameters
|
||||||
|
# @input content: Escaped content
|
||||||
|
function print_fold(nameparam, content, i, s)
|
||||||
|
{
|
||||||
|
i = 74 - length(nameparam)
|
||||||
|
s = substr(content, 1, i)
|
||||||
|
print nameparam s
|
||||||
|
s = substr(content, i+1, 73)
|
||||||
|
i = i + 73
|
||||||
|
while (s)
|
||||||
|
{
|
||||||
|
print " " s
|
||||||
|
s = substr(content, i+1, 73)
|
||||||
|
i = i + 73
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Unescape string
|
||||||
|
#
|
||||||
|
# @local variables: i, c, c2, res
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped string
|
||||||
|
function unescape(str, i, c, c2, res) {
|
||||||
|
for(i = 1; i <= length(str); i++) {
|
||||||
|
c = substr(str, i, 1)
|
||||||
|
if (c != "\\") {
|
||||||
|
res = res c
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
c2 = substr(str, i, 1)
|
||||||
|
if (c2 == "n" || c2 == "N") {
|
||||||
|
res = res "\n"
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
# Alternatively, c2 is "\\" or "," or ";". In each case, append res with
|
||||||
|
# c2. If the strings has been escaped correctly, then the character c2
|
||||||
|
# cannot be anything else. To be fail-safe, simply append res with c2.
|
||||||
|
res = res c2
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
|
# Isolate parameter part of an iCalendar line.
|
||||||
|
#
|
||||||
|
# @input str: String
|
||||||
|
# @return: Parameter part
|
||||||
|
function getparam(str, i) {
|
||||||
|
i = index(str, ";")
|
||||||
|
if (!i)
|
||||||
|
return ""
|
||||||
|
return substr(str, i + 1, index(str, ":") - i)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Isolate content part of an iCalendar line, and unescape.
|
||||||
|
#
|
||||||
|
# @input str: String
|
||||||
|
# @return: Unescaped content part
|
||||||
|
function getcontent(str) {
|
||||||
|
return unescape(substr(str, index(str, ":") + 1))
|
||||||
|
}
|
||||||
|
|
||||||
|
# Time-zone aware parsing of DTSTART or DTEND entries.
|
||||||
|
#
|
||||||
|
# @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) {
|
||||||
|
if (dt_param) {
|
||||||
|
split(dt_param, a, ";")
|
||||||
|
for (i in a) {
|
||||||
|
k = index(a[i], "=")
|
||||||
|
if (substr(a[i], 1, k-1) == "TZID") {
|
||||||
|
tz = "TZ=\"" substr(a[i], k + 1) "\" "
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
# 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
# Map iCalendar duration specification into the format to be used in date (1).
|
||||||
|
#
|
||||||
|
# @local variables: dt, dta, i, n, a, seps
|
||||||
|
# @input duration: iCalendar duration string
|
||||||
|
# @return: relative-date/date-time specification to be used in date (1)
|
||||||
|
function parse_duration(duration, dt, dta, i, n, a, seps) {
|
||||||
|
n = split(duration, a, /[PTWHMSD]/, seps)
|
||||||
|
for (i=2; i<=n; i++) {
|
||||||
|
if(seps[i] == "W") dta["weeks"] = a[i]
|
||||||
|
if(seps[i] == "H") dta["hours"] = a[i]
|
||||||
|
if(seps[i] == "M") dta["minutes"] = a[i]
|
||||||
|
if(seps[i] == "S") dta["seconds"] = a[i]
|
||||||
|
if(seps[i] == "D") dta["days"] = a[i]
|
||||||
|
}
|
||||||
|
dt = a[1] ? a[1] : "+"
|
||||||
|
for (i in dta)
|
||||||
|
dt = dt " " dta[i] " " i
|
||||||
|
return dt
|
||||||
|
}
|
||||||
355
src/main.sh
355
src/main.sh
@@ -2,99 +2,14 @@
|
|||||||
|
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
err() {
|
# Helper functions
|
||||||
echo "❌ $1" >/dev/tty
|
. "sh/helper.sh"
|
||||||
}
|
|
||||||
|
|
||||||
if [ -z "${FZF_VJOUR_USE_EXPORTED:-}" ]; then
|
# Read configuration
|
||||||
# Read configuration
|
. "sh/config.sh"
|
||||||
CONFIGFILE="$HOME/.config/fzf-vjour/config"
|
|
||||||
if [ ! -f "$CONFIGFILE" ]; then
|
|
||||||
err "Configuration '$CONFIGFILE' not found."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
# shellcheck source=/dev/null
|
|
||||||
. "$CONFIGFILE"
|
|
||||||
if [ -z "${ROOT:-}" ] || [ -z "${SYNC_CMD:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
|
|
||||||
err "Configuration is incomplete."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
export ROOT
|
|
||||||
export SYNC_CMD
|
|
||||||
export COLLECTION_LABELS
|
|
||||||
|
|
||||||
# Tools
|
# Load awk scripts
|
||||||
if command -v "fzf" >/dev/null; then
|
. "sh/awkscripts.sh"
|
||||||
FZF="fzf"
|
|
||||||
else
|
|
||||||
err "Did not find the command-line fuzzy finder fzf."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
export FZF
|
|
||||||
|
|
||||||
if command -v "uuidgen" >/dev/null; then
|
|
||||||
UUIDGEN="uuidgen"
|
|
||||||
else
|
|
||||||
err "Did not find the uuidgen command."
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
export UUIDGEN
|
|
||||||
|
|
||||||
if command -v "bat" >/dev/null; then
|
|
||||||
CAT="bat"
|
|
||||||
elif command -v "batcat" >/dev/null; then
|
|
||||||
CAT="batcat"
|
|
||||||
fi
|
|
||||||
CAT=${CAT:+$CAT --color=always --style=numbers --language=md}
|
|
||||||
CAT=${CAT:-cat}
|
|
||||||
export CAT
|
|
||||||
|
|
||||||
### AWK SCRIPTS
|
|
||||||
AWK_ALTERTODO=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/altertodo.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_ALTERTODO
|
|
||||||
|
|
||||||
AWK_EXPORT=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/export.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_EXPORT
|
|
||||||
|
|
||||||
AWK_GET=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/get.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_GET
|
|
||||||
|
|
||||||
AWK_LIST=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/list.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_LIST
|
|
||||||
|
|
||||||
AWK_NEW=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/new.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_NEW
|
|
||||||
|
|
||||||
AWK_UPDATE=$(
|
|
||||||
cat <<'EOF'
|
|
||||||
@@include src/awk/update.awk
|
|
||||||
EOF
|
|
||||||
)
|
|
||||||
export AWK_UPDATE
|
|
||||||
### END OF AWK SCRIPTS
|
|
||||||
FZF_VJOUR_USE_EXPORTED="yes"
|
|
||||||
export FZF_VJOUR_USE_EXPORTED
|
|
||||||
fi
|
|
||||||
|
|
||||||
__lines() {
|
__lines() {
|
||||||
find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \
|
find "$ROOT" -type f -name '*.ics' -print0 | xargs -0 -P 0 \
|
||||||
@@ -110,193 +25,87 @@ __lines() {
|
|||||||
|
|
||||||
# Program starts here
|
# Program starts here
|
||||||
if [ "${1:-}" = "--help" ]; then
|
if [ "${1:-}" = "--help" ]; then
|
||||||
echo "Usage: $0 [OPTION]"
|
shift
|
||||||
echo ""
|
echo "Usage: $0 [--help | --new [FILTER..] | [FILTER..] ]
|
||||||
echo "You may specify at most one option."
|
--help Show this help and exit
|
||||||
echo " --help Show this help and exit"
|
--new Create new entry and do not exit
|
||||||
echo " --tasks Show tasks only"
|
--git-init Activate git usage and exit
|
||||||
echo " --no-tasks Ignore tasks"
|
--git <cmd> Run git command and exit
|
||||||
echo " --notes Show notes only"
|
|
||||||
echo " --no-notes Ignore notes"
|
[FILTER]
|
||||||
echo " --journal Show journal only"
|
You may specify any of these filters. Filters can be negated using the
|
||||||
echo " --no-journal Ignore journal"
|
--no-... versions, e.g., --no-tasks. Multiple filters are applied in
|
||||||
echo " --completed Show completed tasks only"
|
conjuction. By default, the filter --no-completed is used. Note that
|
||||||
echo " --no-completed Ignore completed tasks"
|
--no-completed is not the same as --open, and similarly, --no-open is not the
|
||||||
echo " --new Create new entry"
|
same as --completed.
|
||||||
echo ""
|
|
||||||
echo "The following options are for internal use."
|
--tasks Show tasks only
|
||||||
echo " --reload Reload list"
|
--notes Show notes only
|
||||||
echo " --preview <selection> Generate preview"
|
--journal Show jounral only
|
||||||
echo " --delete <selection> Delete selected entry"
|
--completed Show completed tasks only
|
||||||
echo " --decrease-priority <selection> Decrease priority of selected task"
|
--open Show open tasks only
|
||||||
echo " --increase-priority <selection> Increase priority of selected task"
|
--filter <query> Specify custom query"
|
||||||
echo " --toggle-completed <selection> Toggle completion flag of task"
|
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Command line arguments to be self-contained
|
# iCalendar routines
|
||||||
# Generate preview of file from selection
|
. "sh/icalendar.sh"
|
||||||
if [ "${1:-}" = "--preview" ]; then
|
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
|
||||||
file="$ROOT/$name"
|
|
||||||
awk -v field="DESCRIPTION" "$AWK_GET" "$file" |
|
|
||||||
$CAT
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
# Delete file from selection
|
|
||||||
if [ "${1:-}" = "--delete" ]; then
|
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
|
||||||
file="$ROOT/$name"
|
|
||||||
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file")
|
|
||||||
while true; do
|
|
||||||
printf "Do you want to delete the entry with the title \"%s\"? (yes/no): " "$summary" >/dev/tty
|
|
||||||
read -r yn
|
|
||||||
case $yn in
|
|
||||||
"yes")
|
|
||||||
rm -v "$file"
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
"no")
|
|
||||||
break
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo "Please answer \"yes\" or \"no\"." >/dev/tty
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
# Generate new entry
|
|
||||||
if [ "${1:-}" = "--new" ]; then
|
|
||||||
collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
|
|
||||||
file=""
|
|
||||||
while [ -f "$file" ] || [ -z "$file" ]; do
|
|
||||||
uuid=$($UUIDGEN)
|
|
||||||
file="$ROOT/$collection/$uuid.ics"
|
|
||||||
done
|
|
||||||
tmpmd=$(mktemp --suffix='.md')
|
|
||||||
{
|
|
||||||
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 "# <!-- write summary here -->"
|
|
||||||
echo "> <!-- comma-separated list of categories -->"
|
|
||||||
echo ""
|
|
||||||
} >"$tmpmd"
|
|
||||||
checksum=$(cksum "$tmpmd")
|
|
||||||
|
|
||||||
# Open in editor
|
# Command line arguments: Interal use
|
||||||
$EDITOR "$tmpmd" >/dev/tty
|
. "sh/cliinternal.sh"
|
||||||
|
|
||||||
# Update if changes are detected
|
# Command line arguments: Interal use
|
||||||
if [ "$checksum" != "$(cksum "$tmpmd")" ]; then
|
. "sh/cli.sh"
|
||||||
tmpfile="$tmpmd.ics"
|
|
||||||
awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"
|
while true; do
|
||||||
mv "$tmpfile" "$file"
|
query=$(stripws "$query")
|
||||||
|
selection=$(
|
||||||
|
__lines | $FZF --ansi \
|
||||||
|
--query="$query " \
|
||||||
|
--no-sort \
|
||||||
|
--no-hscroll \
|
||||||
|
--with-nth=5.. \
|
||||||
|
--print-query \
|
||||||
|
--accept-nth=4 \
|
||||||
|
--preview="$0 --preview {4}" \
|
||||||
|
--expect="ctrl-n,ctrl-alt-d" \
|
||||||
|
--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='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 ; printf 'Press <enter> to continue.'; read -r tmp)"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Line 1: query
|
||||||
|
# Line 2: key ("" for enter)
|
||||||
|
# Line 3: relative file path
|
||||||
|
query=$(echo "$selection" | head -n 1)
|
||||||
|
key=$(echo "$selection" | head -n 2 | tail -n 1)
|
||||||
|
fname=$(echo "$selection" | head -n 3 | tail -n 1)
|
||||||
|
if [ "$fname" = "$key" ]; then
|
||||||
|
fname=""
|
||||||
fi
|
fi
|
||||||
rm "$tmpmd"
|
|
||||||
fi
|
|
||||||
# Toggle completed flag
|
|
||||||
if [ "${1:-}" = "--toggle-completed" ]; then
|
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
|
||||||
file="$ROOT/$name"
|
|
||||||
tmpfile=$(mktemp)
|
|
||||||
awk "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
|
||||||
mv "$tmpfile" "$file"
|
|
||||||
fi
|
|
||||||
# Increase priority
|
|
||||||
if [ "${1:-}" = "--increase-priority" ]; then
|
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
|
||||||
file="$ROOT/$name"
|
|
||||||
tmpfile=$(mktemp)
|
|
||||||
awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
|
||||||
mv "$tmpfile" "$file"
|
|
||||||
fi
|
|
||||||
# Decrease priority
|
|
||||||
if [ "${1:-}" = "--decrease-priority" ]; then
|
|
||||||
name=$(echo "$2" | cut -d ' ' -f 3)
|
|
||||||
file="$ROOT/$name"
|
|
||||||
tmpfile=$(mktemp)
|
|
||||||
awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
|
||||||
mv "$tmpfile" "$file"
|
|
||||||
fi
|
|
||||||
if [ "${1:-}" = "--reload" ]; then
|
|
||||||
__lines
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
|
|
||||||
query="${FZF_QUERY:-}"
|
file="$ROOT/$fname"
|
||||||
if [ "${1:-}" = "--no-completed" ]; then
|
if [ ! -f "$file" ]; then
|
||||||
query="!✅"
|
err "File '$file' does not exist!"
|
||||||
fi
|
return 1
|
||||||
if [ "${1:-}" = "--completed" ]; then
|
fi
|
||||||
query="✅"
|
|
||||||
fi
|
|
||||||
if [ "${1:-}" = "--tasks" ]; then
|
|
||||||
query="✅ | 🔲"
|
|
||||||
fi
|
|
||||||
if [ "${1:-}" = "--no-tasks" ]; then
|
|
||||||
query="!✅ !🔲"
|
|
||||||
fi
|
|
||||||
if [ "${1:-}" = "--notes" ]; then
|
|
||||||
query="🗒️"
|
|
||||||
fi
|
|
||||||
if [ "${1:-}" = "--no-notes" ]; then
|
|
||||||
query="!🗒️"
|
|
||||||
fi
|
|
||||||
if [ "${1:-}" = "--journal" ]; then
|
|
||||||
query="📘"
|
|
||||||
fi
|
|
||||||
if [ "${1:-}" = "--no-journal" ]; then
|
|
||||||
query="!📘"
|
|
||||||
fi
|
|
||||||
query=${query:-!✅}
|
|
||||||
query=$(echo "$query" | xargs)
|
|
||||||
|
|
||||||
selection=$(
|
case "$key" in
|
||||||
__lines | $FZF --ansi \
|
"ctrl-n")
|
||||||
--query="$query " \
|
__new
|
||||||
--no-sort \
|
;;
|
||||||
--no-hscroll \
|
"ctrl-alt-d")
|
||||||
--ellipsis='' \
|
__delete "$file"
|
||||||
--with-nth=4.. \
|
;;
|
||||||
--accept-nth=3 \
|
*)
|
||||||
--preview="$0 --preview {}" \
|
__edit "$file"
|
||||||
--bind="ctrl-r:reload-sync($0 --reload)" \
|
;;
|
||||||
--bind="ctrl-alt-d:become($0 --delete {})" \
|
esac
|
||||||
--bind="ctrl-x:become($0 --toggle-completed {})" \
|
done
|
||||||
--bind="alt-up:become($0 --increase-priority {})" \
|
|
||||||
--bind="alt-down:become($0 --decrease-priority {})" \
|
|
||||||
--bind="ctrl-n:become($0 --new)" \
|
|
||||||
--bind="alt-0:change-query(!✅)" \
|
|
||||||
--bind="alt-1:change-query(📘)" \
|
|
||||||
--bind="alt-2:change-query(🗒️)" \
|
|
||||||
--bind="alt-3:change-query(✅ | 🔲)" \
|
|
||||||
--bind="ctrl-s:execute($SYNC_CMD ; printf 'Press <enter> to continue.'; read -r tmp)"
|
|
||||||
)
|
|
||||||
if [ -z "$selection" ]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
file="$ROOT/$selection"
|
|
||||||
|
|
||||||
if [ ! -f "$file" ]; then
|
|
||||||
echo "ERROR: File '$file' does not exist!" >/dev/tty
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Prepare file to be edited
|
|
||||||
filetmp=$(mktemp --suffix='.md')
|
|
||||||
awk "$AWK_EXPORT" "$file" >"$filetmp"
|
|
||||||
checksum=$(cksum "$filetmp")
|
|
||||||
|
|
||||||
# Open in editor
|
|
||||||
$EDITOR "$filetmp" >/dev/tty
|
|
||||||
|
|
||||||
# Update only if changes are detected
|
|
||||||
if [ "$checksum" != "$(cksum "$filetmp")" ]; then
|
|
||||||
file_new="$filetmp.ics"
|
|
||||||
awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
|
|
||||||
mv "$file_new" "$file"
|
|
||||||
fi
|
|
||||||
rm "$filetmp"
|
|
||||||
|
|
||||||
exec "$0"
|
|
||||||
|
|||||||
41
src/sh/awkscripts.sh
Normal file
41
src/sh/awkscripts.sh
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
AWK_ALTERTODO=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/altertodo.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_ALTERTODO
|
||||||
|
|
||||||
|
AWK_EXPORT=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/export.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_EXPORT
|
||||||
|
|
||||||
|
AWK_GET=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/get.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_GET
|
||||||
|
|
||||||
|
AWK_LIST=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/list.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_LIST
|
||||||
|
|
||||||
|
AWK_NEW=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/new.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_NEW
|
||||||
|
|
||||||
|
AWK_UPDATE=$(
|
||||||
|
cat <<'EOF'
|
||||||
|
@@include awk/update.awk
|
||||||
|
EOF
|
||||||
|
)
|
||||||
|
export AWK_UPDATE
|
||||||
94
src/sh/cli.sh
Normal file
94
src/sh/cli.sh
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
# Git
|
||||||
|
if [ "${1:-}" = "--git-init" ]; then
|
||||||
|
shift
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
err "Git already enabled"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if ! command -v "git" >/dev/null; then
|
||||||
|
err "Git not installed"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
git -C "$ROOT" init
|
||||||
|
git -C "$ROOT" add -A
|
||||||
|
git -C "$ROOT" commit -m 'Initial commit: Start git tracking'
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${1:-}" = "--git" ]; then
|
||||||
|
shift
|
||||||
|
if [ -z "${GIT:-}" ]; then
|
||||||
|
err "Git not supported, run \`$0 --git-init\` first"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
$GIT "$@"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Generate new entry
|
||||||
|
if [ "${1:-}" = "--new" ]; then
|
||||||
|
shift
|
||||||
|
__new
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build query
|
||||||
|
while [ -n "${1:-}" ]; do
|
||||||
|
case "${1:-}" in
|
||||||
|
"--completed")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} ✅"
|
||||||
|
;;
|
||||||
|
"--no-completed")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !✅"
|
||||||
|
;;
|
||||||
|
"--open")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} 🔲"
|
||||||
|
;;
|
||||||
|
"--no-open")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !🔲"
|
||||||
|
;;
|
||||||
|
"--tasks")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} ✅ | 🔲"
|
||||||
|
;;
|
||||||
|
"--no-tasks")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !✅ !🔲"
|
||||||
|
;;
|
||||||
|
"--notes")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} 🗒️"
|
||||||
|
;;
|
||||||
|
"--no-notes")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !🗒️"
|
||||||
|
;;
|
||||||
|
"--journal")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} 📘"
|
||||||
|
;;
|
||||||
|
"--no-journal")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !📘"
|
||||||
|
;;
|
||||||
|
"--filter")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} $1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
"--no-filter")
|
||||||
|
shift
|
||||||
|
cliquery="${cliquery:-} !$1"
|
||||||
|
shift
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
err "Unknown option \"$1\""
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
query=${cliquery:-!✅}
|
||||||
|
export query
|
||||||
0
src/sh/cligit.sh
Normal file
0
src/sh/cligit.sh
Normal file
35
src/sh/cliinternal.sh
Normal file
35
src/sh/cliinternal.sh
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
# Command-line interface for internal use only
|
||||||
|
|
||||||
|
# Generate preview of file from selection
|
||||||
|
if [ "${1:-}" = "--preview" ]; then
|
||||||
|
shift
|
||||||
|
name="$1"
|
||||||
|
shift
|
||||||
|
file="$ROOT/$name"
|
||||||
|
awk -v field="DESCRIPTION" "$AWK_GET" "$file" |
|
||||||
|
$CAT
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Reload view
|
||||||
|
if [ "${1:-}" = "--reload" ]; then
|
||||||
|
shift
|
||||||
|
case "${1:-}" in
|
||||||
|
"--toggle-completed")
|
||||||
|
shift
|
||||||
|
fname="$1"
|
||||||
|
shift
|
||||||
|
__toggle_completed "$fname" >/dev/null
|
||||||
|
;;
|
||||||
|
"--change-priority")
|
||||||
|
shift
|
||||||
|
delta=$1
|
||||||
|
shift
|
||||||
|
fname="$1"
|
||||||
|
shift
|
||||||
|
__change_priority "$delta" "$fname" >>/tmp/foo
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
__lines
|
||||||
|
exit
|
||||||
|
fi
|
||||||
45
src/sh/config.sh
Normal file
45
src/sh/config.sh
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
CONFIGFILE="$HOME/.config/fzf-vjour/config"
|
||||||
|
if [ ! -f "$CONFIGFILE" ]; then
|
||||||
|
err "Configuration '$CONFIGFILE' not found."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
. "$CONFIGFILE"
|
||||||
|
if [ -z "${ROOT:-}" ] || [ -z "${SYNC_CMD:-}" ] || [ -z "${COLLECTION_LABELS:-}" ]; then
|
||||||
|
err "Configuration is incomplete."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
export ROOT
|
||||||
|
export SYNC_CMD
|
||||||
|
export COLLECTION_LABELS
|
||||||
|
|
||||||
|
# Tools
|
||||||
|
if command -v "fzf" >/dev/null; then
|
||||||
|
FZF="fzf"
|
||||||
|
else
|
||||||
|
err "Did not find the command-line fuzzy finder fzf."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
export FZF
|
||||||
|
|
||||||
|
if command -v "uuidgen" >/dev/null; then
|
||||||
|
UUIDGEN="uuidgen"
|
||||||
|
else
|
||||||
|
err "Did not find the uuidgen command."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
export UUIDGEN
|
||||||
|
|
||||||
|
if command -v "bat" >/dev/null; then
|
||||||
|
CAT="bat"
|
||||||
|
elif command -v "batcat" >/dev/null; then
|
||||||
|
CAT="batcat"
|
||||||
|
fi
|
||||||
|
CAT=${CAT:+$CAT --color=always --style=numbers --language=md}
|
||||||
|
CAT=${CAT:-cat}
|
||||||
|
export CAT
|
||||||
|
|
||||||
|
if command -v "git" >/dev/null && [ -d "$ROOT/.git" ]; then
|
||||||
|
GIT="git -C $ROOT"
|
||||||
|
fi
|
||||||
|
export GIT
|
||||||
9
src/sh/helper.sh
Normal file
9
src/sh/helper.sh
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Print error message
|
||||||
|
err() {
|
||||||
|
echo "❌ $1" >/dev/tty
|
||||||
|
}
|
||||||
|
|
||||||
|
# Strip whitespaces from argument
|
||||||
|
stripws() {
|
||||||
|
echo "$@" | sed "s/^ *//" | sed "s/ *$//"
|
||||||
|
}
|
||||||
128
src/sh/icalendar.sh
Normal file
128
src/sh/icalendar.sh
Normal file
@@ -0,0 +1,128 @@
|
|||||||
|
# Interface to modify iCalendar files
|
||||||
|
|
||||||
|
# Toggle completed status of VTODO
|
||||||
|
#
|
||||||
|
# @input $1: Relative path to iCalendar file
|
||||||
|
__toggle_completed() {
|
||||||
|
fname="$1"
|
||||||
|
shift
|
||||||
|
file="$ROOT/$fname"
|
||||||
|
tmpfile=$(mktemp)
|
||||||
|
awk "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "Completed toggle" -- "$file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Change priority of VTODO entry
|
||||||
|
#
|
||||||
|
# @input $1: Delta, can be any integer
|
||||||
|
# @input $2: Relative path to iCalendar file
|
||||||
|
__change_priority() {
|
||||||
|
delta=$1
|
||||||
|
shift
|
||||||
|
fname="$1"
|
||||||
|
shift
|
||||||
|
echo "call to __change_priority with delta=$delta and fname=$fname" >>/tmp/foo
|
||||||
|
file="$ROOT/$fname"
|
||||||
|
tmpfile=$(mktemp)
|
||||||
|
echo " tmpfile=$tmpfile" >>/tmp/foo
|
||||||
|
awk -v delta="$delta" "$AWK_ALTERTODO" "$file" >"$tmpfile"
|
||||||
|
echo " lines=$(wc -l tmpfile)" >>/tmp/foo
|
||||||
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "Priority changed by $delta" -- "$file"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Edit file
|
||||||
|
#
|
||||||
|
# @input $1: File path
|
||||||
|
__edit() {
|
||||||
|
file="$1"
|
||||||
|
shift
|
||||||
|
filetmp=$(mktemp --suffix='.md')
|
||||||
|
awk "$AWK_EXPORT" "$file" >"$filetmp"
|
||||||
|
checksum=$(cksum "$filetmp")
|
||||||
|
|
||||||
|
# Open in editor
|
||||||
|
$EDITOR "$filetmp" >/dev/tty
|
||||||
|
|
||||||
|
# Update only if changes are detected
|
||||||
|
if [ "$checksum" != "$(cksum "$filetmp")" ]; then
|
||||||
|
file_new="$filetmp.ics"
|
||||||
|
awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
|
||||||
|
mv "$file_new" "$file"
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "File modified" -- "$file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
rm "$filetmp"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Delete file
|
||||||
|
#
|
||||||
|
# @input $1: File path
|
||||||
|
__delete() {
|
||||||
|
file="$1"
|
||||||
|
shift
|
||||||
|
summary=$(awk -v field="SUMMARY" "$AWK_GET" "$file")
|
||||||
|
while true; do
|
||||||
|
printf "Do you want to delete the entry with the title \"%s\"? (yes/no): " "$summary" >/dev/tty
|
||||||
|
read -r yn
|
||||||
|
case $yn in
|
||||||
|
"yes")
|
||||||
|
rm -v "$file"
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "File deleted" -- "$file"
|
||||||
|
fi
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
"no")
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "Please answer \"yes\" or \"no\"." >/dev/tty
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add file
|
||||||
|
__new() {
|
||||||
|
collection=$(printf "%s" "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1)
|
||||||
|
file=""
|
||||||
|
while [ -f "$file" ] || [ -z "$file" ]; do
|
||||||
|
uuid=$($UUIDGEN)
|
||||||
|
file="$ROOT/$collection/$uuid.ics"
|
||||||
|
done
|
||||||
|
tmpmd=$(mktemp --suffix='.md')
|
||||||
|
{
|
||||||
|
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 "# <!-- write summary here -->"
|
||||||
|
echo "> <!-- comma-separated list of categories -->"
|
||||||
|
echo ""
|
||||||
|
} >"$tmpmd"
|
||||||
|
checksum=$(cksum "$tmpmd")
|
||||||
|
|
||||||
|
# Open in editor
|
||||||
|
$EDITOR "$tmpmd" >/dev/tty
|
||||||
|
|
||||||
|
# Update if changes are detected
|
||||||
|
if [ "$checksum" != "$(cksum "$tmpmd")" ]; then
|
||||||
|
tmpfile="$tmpmd.ics"
|
||||||
|
awk -v uid="$uuid" "$AWK_NEW" "$tmpmd" >"$tmpfile"
|
||||||
|
mv "$tmpfile" "$file"
|
||||||
|
if [ -n "${GIT:-}" ]; then
|
||||||
|
$GIT add "$file"
|
||||||
|
$GIT commit -q -m "File added" -- "$file"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
rm "$tmpmd"
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user