List notes sorted by creation date

This commit is contained in:
Konstantin Nazarov 2021-06-19 20:09:57 +00:00
parent f327471f37
commit 0553a11f92
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 24 additions and 12 deletions

View file

@ -40,7 +40,7 @@ To list all existing notes with their titles:
To select a note with fuzzy search and edit it: To select a note with fuzzy search and edit it:
```sh ```sh
./notes.sh -l | fzf --with-nth="2..-1" | xargs -o ./notes.sh -e ./notes.sh -l | fzf --tac --with-nth="2..-1" | xargs -o ./notes.sh -e
``` ```
## License ## License

View file

@ -490,30 +490,42 @@ list_entries() {
BEGIN { \ BEGIN { \
message_id=0; \ message_id=0; \
subject=0; \ subject=0; \
date=0; \
} \ } \
match(\$0, /^X-Note-Id: .*$/) { \ match(\$0, /^X-Note-Id: .*$/) { \
if (message_id != 0) { \ if (message_id != 0) { \
if (subject !=0)\ if (subject !=0 && date != 0)\
print message_id, subject; \ print date, message_id, subject; \
subject = 0 \ subject = 0; \
date = 0; \
};\ };\
message_id = substr(\$0, 12, RLENGTH-11) \ message_id = substr(\$0, 12, RLENGTH-11); \
} \ } \
match(\$0, /^Subject: .*$/) { \ match(\$0, /^Subject: .*$/) { \
if (subject != 0) { \ if (subject != 0) { \
if (message_id != 0)\ if (message_id != 0 && date != 0)\
print message_id, subject; \ print date, message_id, subject; \
message_id = 0 \ message_id = 0; \
date = 0; \
}; \ }; \
subject = substr(\$0, 10, RLENGTH-9) \ subject = substr(\$0, 10, RLENGTH-9); \
} \
match(\$0, /^X-Date: .*$/) { \
if (date != 0) { \
if (message_id != 0 && subject != 0)\
print date, message_id, subject; \
subject = 0; \
message_id = 0; \
}; \
date = substr(\$0, 9, RLENGTH-8); \
} \ } \
END { \ END { \
if (message_id != 0 && subject != 0)\ if (message_id != 0 && subject != 0 && date != 0)\
print message_id, subject;\ print date, message_id, subject;\
}\ }\
" "
grep -m2 -r -h "^Subject:\|^X-Note-Id:" "$BASEDIR" | awk "$FILTER" grep -m3 -r -h "^Subject:\|^X-Note-Id:\|^X-Date:" "$BASEDIR" | awk "$FILTER" | sort | cut -d " " -f "2-"
} }
export_note() { export_note() {