Parse all todo.txt entries in list() and populate all optional fields - justdoit - Simpler (but with not all the features) reimplementation todo.txt CLI
 (HTM) hg clone https://bitbucket.org/iamleot/justdoit
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) changeset 64cfda888a1f1feac9df932d90383f7b410f3cf7
 (DIR) parent 1e019693d15ae56096f7b735cc272d6a1cbc3970
 (HTM) Author: Leonardo Taccari <iamleot@gmail.com>
       Date:   Sat, 18 Aug 2018 12:32:09 
       
       Parse all todo.txt entries in list() and populate all optional fields
       
       Diffstat:
        t.sh |  60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
        1 files changed, 59 insertions(+), 1 deletions(-)
       ---
       diff -r 1e019693d15a -r 64cfda888a1f t.sh
       --- a/t.sh      Sat Aug 18 01:30:53 2018 +0200
       +++ b/t.sh      Sat Aug 18 12:32:09 2018 +0200
       @@ -100,6 +100,10 @@
        {
        
               awk '
       +       BEGIN {
       +               FS = " "
       +       }
       +
               function bold(s) {
                       return sprintf("\033[1m%s\033[0m", s);
               }
       @@ -108,11 +112,65 @@
                       return sprintf("\033[4m%s\033[0m", s);
               }
        
       +       #
       +       # Parse the entry and populate all optional and non-optional fields
       +       #
       +       # Every line of todo.txt file should have the following format:
       +       #
       +       #  +------------+------------+-----------------+---------------+-------------+
       +       #  | completion |  priority  | completion date | creation date | description |
       +       #  | (optional) | (optional) |   (optional)    |  (optional)   |             |
       +       #  +------------+------------+-----------------+---------------+-------------+
       +       #
       +       # where:
       +       #  - completion: just a lower-case "x" to mark that a task is done
       +       #  - priority: a upper-case letter under parethenses (e.g. "(A)")
       +       #  - completion date: date of completion of the task in the %Y-%m-%d
       +       #                     format (e.g. "2018-08-18")
       +       #  - creation date: date of creation of the task in the %Y-%m-%d
       +       #                   format (e.g. "2018-08-18")
       +       #  - description: text of the task; can contain multiple +project_tag,
       +       #                 @context_tag, special key/value tag (key:value)
       +       #
       +       {
       +               completion = ""
       +               priority = ""
       +               completion_date = ""
       +               creation_date = ""
       +               description = ""
       +
       +               i = 1
       +
       +               if ($i == "x") {
       +                       completion = "x"
       +                       i++
       +               }
       +               if (match($i, /\([A-Z]\)/)) {
       +                       priority = $i
       +                       i++
       +               }
       +               if (completion && match($i, /[0-9]+-[0-9]+-[0-9]+/)) {
       +                       completion_date = $i
       +                       i++
       +               }
       +               if (match($i, /[0-9]+-[0-9]+-[0-9]+/)) {
       +                       creation_date = $i
       +                       i++
       +               }
       +
       +               # Remove any non-description fields and possible leading spaces
       +               for (j = 1; j < i; j++) {
       +                       $j = ""
       +               }
       +               sub(/^ +/, "")
       +               description = $0
       +       }
       +
               {
                       # bold all the tags
                       gsub(/@[^ ]+/, "\033[1m&\033[0m")
        
       -               printf("%12s %s\n", underline(NR), $0)
       +               printf("%12s %s\n", underline(NR), description)
               }
               '
        }