From a9bdca55b586c3f1ed67d9208b2c7724bd52c9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Thu, 3 Jul 2025 09:55:22 +0200 Subject: [PATCH] impr: externaliezed and two little bug fixes --- scripts/build.sh | 14 ++++++++++--- src/awk/export.awk | 4 ++-- src/awk/list.awk | 4 +--- src/awk/new.awk | 8 ++++---- src/awk/update.awk | 50 ++++------------------------------------------ src/main.sh | 14 ++++++------- 6 files changed, 29 insertions(+), 65 deletions(-) diff --git a/scripts/build.sh b/scripts/build.sh index 6ebb945..2f8fa35 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -5,7 +5,15 @@ GREEN="\033[0;32m" OFF="\033[m" NAME="fzf-vjour" 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" -echo "🥚 ${GREEN}Done${OFF}" +rm -rf "$tmpdir" +echo "🍳 ${GREEN}Done:${OFF} Sucessfully built ${BOLD}${GREEN}$NAME${OFF}" diff --git a/src/awk/export.awk b/src/awk/export.awk index 4985e29..a7f816f 100644 --- a/src/awk/export.awk +++ b/src/awk/export.awk @@ -11,8 +11,8 @@ END { exit # Process content lines, force CATEGORIES and SUMMARY as single-line c["CATEGORIES"] = singleline(getcontent(c["CATEGORIES"])) - c["DESCRIPTION"] = singleline(getcontent(c["DESCRIPTION"])) - c["SUMMARY"] = getcontent(c["SUMMARY"]) + c["DESCRIPTION"] = getcontent(c["DESCRIPTION"]) + c["SUMMARY"] = singleline(getcontent(c["SUMMARY"])) c["DUE"] = getcontent(c["DUE"]) # Print if (c["DUE"]) diff --git a/src/awk/list.awk b/src/awk/list.awk index f4a7d2b..dfc4e38 100644 --- a/src/awk/list.awk +++ b/src/awk/list.awk @@ -5,7 +5,6 @@ @include "lib/awk/icalendar.awk" -# formatdate # Generate kind-of-pretty date strings. # # @local variables: ts, ts_y, ts_m, ts_d, delta @@ -86,7 +85,7 @@ BEGINFILE { 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; c[prop] = $0; next; @@ -122,7 +121,6 @@ ENDFILE { # Process content lines # strings cat = singleline(unescape(getcontent(c["CATEGORIES"]))) - des = singleline(unescape(getcontent(c["DESCRIPTION"]))) sta = singleline(unescape(getcontent(c["STATUS"]))) sum = singleline(unescape(getcontent(c["SUMMARY"]))) diff --git a/src/awk/new.awk b/src/awk/new.awk index f6bfc39..635b633 100644 --- a/src/awk/new.awk +++ b/src/awk/new.awk @@ -20,10 +20,10 @@ desc { desc = desc "\\n" escape($0); next; } } summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3)); 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; # First line of description - desc = escape($0); + desc = "D" escape($0); next; } END { @@ -39,7 +39,7 @@ END { print "BEGIN:VCALENDAR"; print "VERSION:2.0"; print "CALSCALE:GREGORIAN"; - print "PRODID:-//fab//awk//EN"; + print "PRODID:-//fzf-vjour//awk//EN"; print "BEGIN:" type; print "DTSTAMP:" zulu; print "UID:" uid; @@ -62,7 +62,7 @@ END { } if (summary) print_fold("SUMMARY:", summary); 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:VCALENDAR" } diff --git a/src/awk/update.awk b/src/awk/update.awk index 89e3762..69fb846 100644 --- a/src/awk/update.awk +++ b/src/awk/update.awk @@ -1,46 +1,4 @@ -# Escape string to be used as content in iCalendar files. -# -# @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 - } -} +@include "lib/awk/icalendar.awk" BEGIN { FS=":"; @@ -69,10 +27,10 @@ NR == FNR { } summary = substr($0, 1, 2) != "# " ? "" : escape(substr($0, 3)); 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; # First line of description - desc = escape($0); + desc = "D" escape($0); next; } @@ -88,7 +46,7 @@ NR == FNR { if (due) print "DUE;VALUE=DATE:" due; print_fold("SUMMARY:", summary); print_fold("CATEGORIES:", categories); - print_fold("DESCRIPTION:", desc); + print_fold("DESCRIPTION:", substr(desc, 2)); type = ""; } { print } diff --git a/src/main.sh b/src/main.sh index 932899b..29567cd 100644 --- a/src/main.sh +++ b/src/main.sh @@ -52,42 +52,42 @@ if [ -z "${FZF_VJOUR_USE_EXPORTED:-}" ]; then ### AWK SCRIPTS AWK_ALTERTODO=$( cat <<'EOF' -@@include src/awk/altertodo.awk +@@include awk/altertodo.awk EOF ) export AWK_ALTERTODO AWK_EXPORT=$( cat <<'EOF' -@@include src/awk/export.awk +@@include awk/export.awk EOF ) export AWK_EXPORT AWK_GET=$( cat <<'EOF' -@@include src/awk/get.awk +@@include awk/get.awk EOF ) export AWK_GET AWK_LIST=$( cat <<'EOF' -@@include src/awk/list.awk +@@include awk/list.awk EOF ) export AWK_LIST AWK_NEW=$( cat <<'EOF' -@@include src/awk/new.awk +@@include awk/new.awk EOF ) export AWK_NEW AWK_UPDATE=$( cat <<'EOF' -@@include src/awk/update.awk +@@include awk/update.awk EOF ) export AWK_UPDATE @@ -204,7 +204,7 @@ fi # Generate new entry if [ "${1:-}" = "--new" ]; then shift - collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1) + collection=$(printf "%s" "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1) file="" while [ -f "$file" ] || [ -z "$file" ]; do uuid=$($UUIDGEN)