impr: externaliezed and two little bug fixes

This commit is contained in:
2025-07-03 09:55:22 +02:00
parent 0dd0a81a64
commit a9bdca55b5
6 changed files with 29 additions and 65 deletions

View File

@@ -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}"

View File

@@ -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"])

View File

@@ -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"])))

View File

@@ -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"
}

View File

@@ -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 }

View File

@@ -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)