Compare commits
	
		
			4 Commits
		
	
	
		
			c63b3c4ee2
			...
			c8f88b2410
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c8f88b2410 | |||
| a9bdca55b5 | |||
| 0dd0a81a64 | |||
| 53149ea9db | 
@@ -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,38 +1,4 @@
 | 
				
			|||||||
# unescape
 | 
					@include "lib/awk/icalendar.awk"
 | 
				
			||||||
# Isolate and unescape the content part of an iCalendar line.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @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
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# getcontent
 | 
					 | 
				
			||||||
# 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))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
BEGIN                     { FS = "[:;]"; }
 | 
					BEGIN                     { FS = "[:;]"; }
 | 
				
			||||||
/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
 | 
					/^BEGIN:(VJOURNAL|VTODO)/ { type = $2 }
 | 
				
			||||||
@@ -43,10 +9,10 @@ BEGIN                     { FS = "[:;]"; }
 | 
				
			|||||||
END {
 | 
					END {
 | 
				
			||||||
  if (!type)
 | 
					  if (!type)
 | 
				
			||||||
    exit
 | 
					    exit
 | 
				
			||||||
  # Process content lines
 | 
					  # Process content lines, force CATEGORIES and SUMMARY as single-line
 | 
				
			||||||
  c["CATEGORIES"]  = getcontent(c["CATEGORIES"])
 | 
					  c["CATEGORIES"]  = singleline(getcontent(c["CATEGORIES"]))
 | 
				
			||||||
  c["DESCRIPTION"] = getcontent(c["DESCRIPTION"])
 | 
					  c["DESCRIPTION"] = getcontent(c["DESCRIPTION"])
 | 
				
			||||||
  c["SUMMARY"]     = getcontent(c["SUMMARY"])
 | 
					  c["SUMMARY"]     = singleline(getcontent(c["SUMMARY"]))
 | 
				
			||||||
  c["DUE"]         = getcontent(c["DUE"])
 | 
					  c["DUE"]         = getcontent(c["DUE"])
 | 
				
			||||||
  # Print
 | 
					  # Print
 | 
				
			||||||
  if (c["DUE"])
 | 
					  if (c["DUE"])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,38 +1,4 @@
 | 
				
			|||||||
# unescape
 | 
					@include "lib/awk/icalendar.awk"
 | 
				
			||||||
# Isolate and unescape the content part of an iCalendar line.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @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
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# getcontent
 | 
					 | 
				
			||||||
# 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))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# print content of field `field`
 | 
					# print content of field `field`
 | 
				
			||||||
BEGIN                     { FS = ":"; regex = "^" field; }
 | 
					BEGIN                     { FS = ":"; regex = "^" field; }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,50 +3,8 @@
 | 
				
			|||||||
# 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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Make string single-line
 | 
					@include "lib/awk/icalendar.awk"
 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @input str: String
 | 
					 | 
				
			||||||
# @return: String without newlines
 | 
					 | 
				
			||||||
function singleline(str) {
 | 
					 | 
				
			||||||
  gsub("\\n", " ", str)
 | 
					 | 
				
			||||||
  return str
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Isolate and unescape the content part of an iCalendar line.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @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 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))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# formatdate
 | 
					 | 
				
			||||||
# Generate kind-of-pretty date strings.
 | 
					# Generate kind-of-pretty date strings.
 | 
				
			||||||
#
 | 
					#
 | 
				
			||||||
# @local variables: ts, ts_y, ts_m, ts_d, delta
 | 
					# @local variables: ts, ts_y, ts_m, ts_d, delta
 | 
				
			||||||
@@ -127,7 +85,7 @@ 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;
 | 
				
			||||||
  c[prop] = $0;
 | 
					  c[prop] = $0;
 | 
				
			||||||
  next;
 | 
					  next;
 | 
				
			||||||
@@ -163,7 +121,6 @@ ENDFILE {
 | 
				
			|||||||
  # Process content lines
 | 
					  # Process content lines
 | 
				
			||||||
  # strings
 | 
					  # strings
 | 
				
			||||||
  cat = singleline(unescape(getcontent(c["CATEGORIES"])))
 | 
					  cat = singleline(unescape(getcontent(c["CATEGORIES"])))
 | 
				
			||||||
  des = singleline(unescape(getcontent(c["DESCRIPTION"])))
 | 
					 | 
				
			||||||
  sta = singleline(unescape(getcontent(c["STATUS"])))
 | 
					  sta = singleline(unescape(getcontent(c["STATUS"])))
 | 
				
			||||||
  sum = singleline(unescape(getcontent(c["SUMMARY"])))
 | 
					  sum = singleline(unescape(getcontent(c["SUMMARY"])))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,46 +1,4 @@
 | 
				
			|||||||
# Escape string to be used as content in iCalendar files.
 | 
					@include "lib/awk/icalendar.awk"
 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @input str: String to escape
 | 
					 | 
				
			||||||
# @return: Escaped string
 | 
					 | 
				
			||||||
function escape(str)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  gsub("\\\\", "\\\\", str)
 | 
					 | 
				
			||||||
  gsub(";",    "\\;",  str)
 | 
					 | 
				
			||||||
  gsub(",",    "\\,",  str)
 | 
					 | 
				
			||||||
  return str
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Escape string to be used as content in iCalendar files.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @input str: String to escape
 | 
					 | 
				
			||||||
# @return: Escaped string
 | 
					 | 
				
			||||||
function escape_categories(str)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  gsub("\\\\", "\\\\", 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
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
BEGIN { 
 | 
					BEGIN { 
 | 
				
			||||||
  FS=":"; 
 | 
					  FS=":"; 
 | 
				
			||||||
@@ -62,10 +20,10 @@ desc { desc = desc "\\n" escape($0); next; }
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
 | 
					  summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
 | 
				
			||||||
  getline;
 | 
					  getline;
 | 
				
			||||||
  categories = substr($0, 1, 1) != ">" ? "" : escape(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 = escape($0);
 | 
					  desc = "D" escape($0);
 | 
				
			||||||
  next;
 | 
					  next;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
END {
 | 
					END {
 | 
				
			||||||
@@ -81,7 +39,7 @@ END {
 | 
				
			|||||||
  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;
 | 
				
			||||||
@@ -104,7 +62,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:", desc);
 | 
					  if (desc)       print_fold("DESCRIPTION:", substr(desc, 2));
 | 
				
			||||||
  print "END:" type;
 | 
					  print "END:" type;
 | 
				
			||||||
  print "END:VCALENDAR"
 | 
					  print "END:VCALENDAR"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,46 +1,4 @@
 | 
				
			|||||||
# Escape string to be used as content in iCalendar files.
 | 
					@include "lib/awk/icalendar.awk"
 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @input str: String to escape
 | 
					 | 
				
			||||||
# @return: Escaped string
 | 
					 | 
				
			||||||
function escape(str)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  gsub("\\\\", "\\\\", str)
 | 
					 | 
				
			||||||
  gsub(";",    "\\;",  str)
 | 
					 | 
				
			||||||
  gsub(",",    "\\,",  str)
 | 
					 | 
				
			||||||
  return str
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
# Escape string to be used as content in iCalendar files.
 | 
					 | 
				
			||||||
#
 | 
					 | 
				
			||||||
# @input str: String to escape
 | 
					 | 
				
			||||||
# @return: Escaped string
 | 
					 | 
				
			||||||
function escape_categories(str)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
  gsub("\\\\", "\\\\", 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
 | 
					 | 
				
			||||||
  }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
BEGIN { 
 | 
					BEGIN { 
 | 
				
			||||||
  FS=":";
 | 
					  FS=":";
 | 
				
			||||||
@@ -69,10 +27,10 @@ NR == FNR {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
  summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
 | 
					  summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3));
 | 
				
			||||||
  getline;
 | 
					  getline;
 | 
				
			||||||
  categories = substr($0, 1, 1) != ">" ? "" : escape_categories(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 = escape($0);
 | 
					  desc = "D" escape($0);
 | 
				
			||||||
  next;
 | 
					  next;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -88,7 +46,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:", desc);
 | 
					  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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										239
									
								
								src/main.sh
									
									
									
									
									
								
							
							
						
						
									
										239
									
								
								src/main.sh
									
									
									
									
									
								
							@@ -8,90 +8,11 @@ err() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
if [ -z "${FZF_VJOUR_USE_EXPORTED:-}" ]; then
 | 
					if [ -z "${FZF_VJOUR_USE_EXPORTED:-}" ]; then
 | 
				
			||||||
  # Read configuration
 | 
					  # Read configuration
 | 
				
			||||||
  CONFIGFILE="$HOME/.config/fzf-vjour/config"
 | 
					  . "sh/config.sh"
 | 
				
			||||||
  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"
 | 
					  FZF_VJOUR_USE_EXPORTED="yes"
 | 
				
			||||||
  export FZF_VJOUR_USE_EXPORTED
 | 
					  export FZF_VJOUR_USE_EXPORTED
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
@@ -134,155 +55,13 @@ if [ "${1:-}" = "--help" ]; then
 | 
				
			|||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Git
 | 
					# Git
 | 
				
			||||||
if command -v "git" >/dev/null && [ -d "$ROOT/.git" ]; then
 | 
					. "sh/cligit.sh"
 | 
				
			||||||
  GIT="git -C $ROOT"
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
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
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Command line arguments to be self-contained
 | 
					# Command line arguments: Interal use
 | 
				
			||||||
# Generate preview of file from selection
 | 
					. "sh/cli.sh"
 | 
				
			||||||
if [ "${1:-}" = "--preview" ]; then
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  file="$ROOT/$name"
 | 
					 | 
				
			||||||
  awk -v field="DESCRIPTION" "$AWK_GET" "$file" |
 | 
					 | 
				
			||||||
    $CAT
 | 
					 | 
				
			||||||
  exit
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
# Delete file from selection
 | 
					 | 
				
			||||||
if [ "${1:-}" = "--delete" ]; then
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  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"
 | 
					 | 
				
			||||||
      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
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
# Generate new entry
 | 
					 | 
				
			||||||
if [ "${1:-}" = "--new" ]; then
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  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
 | 
					 | 
				
			||||||
  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"
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
# Toggle completed flag
 | 
					 | 
				
			||||||
if [ "${1:-}" = "--toggle-completed" ]; then
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  file="$ROOT/$name"
 | 
					 | 
				
			||||||
  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
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
# Increase priority
 | 
					 | 
				
			||||||
if [ "${1:-}" = "--increase-priority" ]; then
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  file="$ROOT/$name"
 | 
					 | 
				
			||||||
  tmpfile=$(mktemp)
 | 
					 | 
				
			||||||
  awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
 | 
					 | 
				
			||||||
  mv "$tmpfile" "$file"
 | 
					 | 
				
			||||||
  if [ -n "$GIT" ]; then
 | 
					 | 
				
			||||||
    $GIT add "$file"
 | 
					 | 
				
			||||||
    $GIT commit -q -m "Priority increased" -- "$file"
 | 
					 | 
				
			||||||
  fi
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
# Decrease priority
 | 
					 | 
				
			||||||
if [ "${1:-}" = "--decrease-priority" ]; then
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  file="$ROOT/$name"
 | 
					 | 
				
			||||||
  tmpfile=$(mktemp)
 | 
					 | 
				
			||||||
  awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
 | 
					 | 
				
			||||||
  mv "$tmpfile" "$file"
 | 
					 | 
				
			||||||
  if [ -n "$GIT" ]; then
 | 
					 | 
				
			||||||
    $GIT add "$file"
 | 
					 | 
				
			||||||
    $GIT commit -q -m "Priority decreased" -- "$file"
 | 
					 | 
				
			||||||
  fi
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
# Reload view
 | 
					 | 
				
			||||||
if [ "${1:-}" = "--reload" ]; then
 | 
					 | 
				
			||||||
  shift
 | 
					 | 
				
			||||||
  __lines
 | 
					 | 
				
			||||||
  exit
 | 
					 | 
				
			||||||
fi
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
while [ -n "${1:-}" ]; do
 | 
					while [ -n "${1:-}" ]; do
 | 
				
			||||||
  case "${1:-}" in
 | 
					  case "${1:-}" in
 | 
				
			||||||
@@ -390,7 +169,7 @@ if [ "$checksum" != "$(cksum "$filetmp")" ]; then
 | 
				
			|||||||
  file_new="$filetmp.ics"
 | 
					  file_new="$filetmp.ics"
 | 
				
			||||||
  awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
 | 
					  awk "$AWK_UPDATE" "$filetmp" "$file" >"$file_new"
 | 
				
			||||||
  mv "$file_new" "$file"
 | 
					  mv "$file_new" "$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
 | 
					  fi
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										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
 | 
				
			||||||
							
								
								
									
										34
									
								
								src/sh/cli.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/sh/cli.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					# Generate new entry
 | 
				
			||||||
 | 
					if [ "${1:-}" = "--new" ]; then
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  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"
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
							
								
								
									
										25
									
								
								src/sh/cligit.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/sh/cligit.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
				
			|||||||
 | 
					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
 | 
				
			||||||
							
								
								
									
										93
									
								
								src/sh/cliinternal.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										93
									
								
								src/sh/cliinternal.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,93 @@
 | 
				
			|||||||
 | 
					# Command-line interface for internal use only
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Generate preview of file from selection
 | 
				
			||||||
 | 
					if [ "${1:-}" = "--preview" ]; then
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  file="$ROOT/$name"
 | 
				
			||||||
 | 
					  awk -v field="DESCRIPTION" "$AWK_GET" "$file" |
 | 
				
			||||||
 | 
					    $CAT
 | 
				
			||||||
 | 
					  exit
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Delete file from selection
 | 
				
			||||||
 | 
					if [ "${1:-}" = "--delete" ]; then
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  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"
 | 
				
			||||||
 | 
					      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
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Toggle completed flag
 | 
				
			||||||
 | 
					if [ "${1:-}" = "--toggle-completed" ]; then
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  file="$ROOT/$name"
 | 
				
			||||||
 | 
					  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
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Increase priority
 | 
				
			||||||
 | 
					if [ "${1:-}" = "--increase-priority" ]; then
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  file="$ROOT/$name"
 | 
				
			||||||
 | 
					  tmpfile=$(mktemp)
 | 
				
			||||||
 | 
					  awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
 | 
				
			||||||
 | 
					  mv "$tmpfile" "$file"
 | 
				
			||||||
 | 
					  if [ -n "${GIT:-}" ]; then
 | 
				
			||||||
 | 
					    $GIT add "$file"
 | 
				
			||||||
 | 
					    $GIT commit -q -m "Priority increased" -- "$file"
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Decrease priority
 | 
				
			||||||
 | 
					if [ "${1:-}" = "--decrease-priority" ]; then
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  name=$(echo "$1" | cut -d ' ' -f 3)
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  file="$ROOT/$name"
 | 
				
			||||||
 | 
					  tmpfile=$(mktemp)
 | 
				
			||||||
 | 
					  awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile"
 | 
				
			||||||
 | 
					  mv "$tmpfile" "$file"
 | 
				
			||||||
 | 
					  if [ -n "${GIT:-}" ]; then
 | 
				
			||||||
 | 
					    $GIT add "$file"
 | 
				
			||||||
 | 
					    $GIT commit -q -m "Priority decreased" -- "$file"
 | 
				
			||||||
 | 
					  fi
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Reload view
 | 
				
			||||||
 | 
					if [ "${1:-}" = "--reload" ]; then
 | 
				
			||||||
 | 
					  shift
 | 
				
			||||||
 | 
					  __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
 | 
				
			||||||
		Reference in New Issue
	
	Block a user