Compare commits
2 Commits
e80d9deb79
...
f663c200d2
| Author | SHA1 | Date | |
|---|---|---|---|
| f663c200d2 | |||
| 78d0983464 |
@@ -87,6 +87,7 @@ 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-1` | Display journal entries |
|
||||||
@@ -99,8 +100,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 |
|
||||||
|
|||||||
@@ -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"])))
|
||||||
|
|
||||||
|
|||||||
@@ -4,25 +4,36 @@ BEGIN {
|
|||||||
FS=":";
|
FS=":";
|
||||||
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; }
|
/^::: \|>/ && !start { gsub("\"", ""); start = substr(zulu, 1, 8); next; }
|
||||||
/^::: <\| / && !due { gsub("\"", ""); due = substr($0, 8); next; }
|
/^::: <\|/ && !due { gsub("\"", ""); due = "D" substr($0, 8); next; }
|
||||||
/^# / && !summary { summary = escape(substr($0, 3)); next; }
|
/^# / && !summary { summary = "S" escape(substr($0, 3)); next; }
|
||||||
/^> / && !categories { categories = escape_but_commas(substr($0, 3)); next; }
|
/^> / && !categories { categories = "C" escape_but_commas(substr($0, 3)); next; }
|
||||||
!$0 && !el { el = 1; next; }
|
!$0 && !el { el = 1; next; }
|
||||||
!el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
|
!el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
|
||||||
{ desc = "D" escape($0); next; }
|
{ desc = "D" escape($0); next; }
|
||||||
END {
|
END {
|
||||||
# Sanitize input
|
# Sanitize input
|
||||||
type = due ? "VTODO" : "VJOURNAL"
|
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\"";
|
||||||
suc = cmd | getline res
|
suc = cmd | getline due
|
||||||
close(cmd)
|
close(cmd)
|
||||||
if (suc != 1)
|
if (suc != 1)
|
||||||
exit 1
|
exit 1
|
||||||
due = res ? res : ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# print ical
|
# print ical
|
||||||
@@ -52,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,30 +6,44 @@ BEGIN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ENDFILE {
|
ENDFILE {
|
||||||
if (NR == FNR && due) {
|
if (NR == FNR) {
|
||||||
# Use command line `date` for parsing
|
due = substr(due, 2)
|
||||||
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
|
summary = substr(summary, 2)
|
||||||
suc = cmd | getline res
|
categories = substr(categories, 2)
|
||||||
close(cmd)
|
desc = substr(desc, 2)
|
||||||
if (suc != 1)
|
if (categories) {
|
||||||
exit 1
|
split(categories, a, ",")
|
||||||
due = res ? res : ""
|
categories = ""
|
||||||
|
for (i in a)
|
||||||
|
if (a[i])
|
||||||
|
categories = categories "," a[i]
|
||||||
|
categories = substr(categories, 2)
|
||||||
|
}
|
||||||
|
if (due) {
|
||||||
|
# Use command line `date` for parsing
|
||||||
|
cmd = "date -d \"" due "\" +\"%Y%m%d\"";
|
||||||
|
suc = cmd | getline due
|
||||||
|
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 && /^::: <\| / && !due { gsub("\"",""); due = substr($0, 8); next; }
|
NR == FNR && /^::: <\|/ && !due { gsub("\"",""); due = "D" substr($0, 8); next; }
|
||||||
NR == FNR && /^# / && !summary { summary = escape(substr($0, 3)); next; }
|
NR == FNR && /^# / && !summary { summary = "S" escape(substr($0, 3)); next; }
|
||||||
NR == FNR && /^> / && !categories { categories = escape_but_commas(substr($0, 3)); next; }
|
NR == FNR && /^> / && !categories { categories = "C" escape_but_commas(substr($0, 3)); next; }
|
||||||
NR == FNR && !$0 && !el { el = 1; next; }
|
NR == FNR && !$0 && !el { el = 1; next; }
|
||||||
NR == FNR && !el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
|
NR == FNR && !el { print "Unrecognized header on line "NR": " $0 > "/dev/stderr"; exit 1; }
|
||||||
NR == FNR { desc = "D" escape($0); next; }
|
NR == FNR { desc = "D" escape($0); next; }
|
||||||
due && type == "VJOURNAL" { print "Notes and journal entries do not have due dates." > "/dev/stderr"; exit 1; }
|
due && type == "VJOURNAL" { print "Notes and journal entries do not have due dates." > "/dev/stderr"; exit 1; }
|
||||||
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2; print; next; }
|
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2; print; next; }
|
||||||
/^X-ALT-DESC/ && type { next; } # drop this alternative description
|
/^ / && drop { next; } # drop this folded line
|
||||||
/^ / && type { next; } # drop this folded line (the only content with folded lines will be updated)
|
/^X-ALT-DESC/ && type { drop = 1; next; } # drop this alternative description
|
||||||
/^(DUE|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && type { next; } # skip for now, we will write updated fields at the end
|
/^(DUE|SUMMARY|CATEGORIES|DESCRIPTION|LAST-MODIFIED)/ && type { drop = 1; next; } # skip for now, we will write updated fields at the end
|
||||||
/^SEQUENCE/ && type { seq = $2; next; } # store sequence number and skip
|
{ drop = 0 } # keep everything else
|
||||||
|
/^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;
|
||||||
@@ -37,7 +51,7 @@ due && type == "VJOURNAL" { print "Notes and journal entries do not have
|
|||||||
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).
|
||||||
|
|||||||
10
src/main.sh
10
src/main.sh
@@ -70,6 +70,9 @@ fi
|
|||||||
# Attachment handling
|
# Attachment handling
|
||||||
. "sh/attachment.sh"
|
. "sh/attachment.sh"
|
||||||
|
|
||||||
|
# Categories handling
|
||||||
|
. "sh/categories.sh"
|
||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
query=$(stripws "$query")
|
query=$(stripws "$query")
|
||||||
selection=$(
|
selection=$(
|
||||||
@@ -81,7 +84,7 @@ 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})" \
|
||||||
@@ -91,7 +94,7 @@ while true; do
|
|||||||
--bind="alt-2:change-query(🗒️)" \
|
--bind="alt-2:change-query(🗒️)" \
|
||||||
--bind="alt-3: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='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="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
|
true
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -120,6 +123,9 @@ while true; do
|
|||||||
"ctrl-a")
|
"ctrl-a")
|
||||||
__attachment_view "$file"
|
__attachment_view "$file"
|
||||||
;;
|
;;
|
||||||
|
"ctrl-t")
|
||||||
|
query="'$(__select_category)'"
|
||||||
|
;;
|
||||||
"")
|
"")
|
||||||
__edit "$file"
|
__edit "$file"
|
||||||
;;
|
;;
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
17
src/sh/categories.sh
Normal file
17
src/sh/categories.sh
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
# 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 --prompt="Select category> " \
|
||||||
|
--no-sort \
|
||||||
|
--tac \
|
||||||
|
--margin="30%,30%" \
|
||||||
|
--border=bold \
|
||||||
|
--border-label="Categories" ||
|
||||||
|
true
|
||||||
|
}
|
||||||
@@ -42,7 +42,16 @@ __edit() {
|
|||||||
file="$1"
|
file="$1"
|
||||||
shift
|
shift
|
||||||
tmpmd=$(mktemp --suffix='.md')
|
tmpmd=$(mktemp --suffix='.md')
|
||||||
awk "$AWK_EXPORT" "$file" >"$tmpmd"
|
due=$(awk -v field="DUE" -v format="date" "$AWK_GET" "$file")
|
||||||
|
if [ -n "$due" ]; then
|
||||||
|
echo "::: <| $due" >"$tmpmd"
|
||||||
|
fi
|
||||||
|
{
|
||||||
|
echo "# $(awk -v field="SUMMARY" -v oneline=1 "$AWK_GET" "$file")"
|
||||||
|
echo "> $(awk -v field="CATEGORIES" -v format="csv" -v oneline=1 "$AWK_GET" "$file")"
|
||||||
|
echo ""
|
||||||
|
awk -v field="DESCRIPTION" "$AWK_GET" "$file"
|
||||||
|
} >>"$tmpmd"
|
||||||
checksum=$(cksum "$tmpmd")
|
checksum=$(cksum "$tmpmd")
|
||||||
|
|
||||||
# Open in editor
|
# Open in editor
|
||||||
|
|||||||
Reference in New Issue
Block a user