impr: externaliezed and two little bug fixes
This commit is contained in:
@@ -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}"
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ END {
|
|||||||
exit
|
exit
|
||||||
# Process content lines, force CATEGORIES and SUMMARY as single-line
|
# Process content lines, force CATEGORIES and SUMMARY as single-line
|
||||||
c["CATEGORIES"] = singleline(getcontent(c["CATEGORIES"]))
|
c["CATEGORIES"] = singleline(getcontent(c["CATEGORIES"]))
|
||||||
c["DESCRIPTION"] = singleline(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"])
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
|
|
||||||
@include "lib/awk/icalendar.awk"
|
@include "lib/awk/icalendar.awk"
|
||||||
|
|
||||||
# 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
|
||||||
@@ -86,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;
|
||||||
@@ -122,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"])))
|
||||||
|
|
||||||
|
|||||||
@@ -20,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 {
|
||||||
@@ -39,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;
|
||||||
@@ -62,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 }
|
||||||
|
|||||||
14
src/main.sh
14
src/main.sh
@@ -52,42 +52,42 @@ if [ -z "${FZF_VJOUR_USE_EXPORTED:-}" ]; then
|
|||||||
### AWK SCRIPTS
|
### AWK SCRIPTS
|
||||||
AWK_ALTERTODO=$(
|
AWK_ALTERTODO=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include src/awk/altertodo.awk
|
@@include awk/altertodo.awk
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
export AWK_ALTERTODO
|
export AWK_ALTERTODO
|
||||||
|
|
||||||
AWK_EXPORT=$(
|
AWK_EXPORT=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include src/awk/export.awk
|
@@include awk/export.awk
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
export AWK_EXPORT
|
export AWK_EXPORT
|
||||||
|
|
||||||
AWK_GET=$(
|
AWK_GET=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include src/awk/get.awk
|
@@include awk/get.awk
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
export AWK_GET
|
export AWK_GET
|
||||||
|
|
||||||
AWK_LIST=$(
|
AWK_LIST=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include src/awk/list.awk
|
@@include awk/list.awk
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
export AWK_LIST
|
export AWK_LIST
|
||||||
|
|
||||||
AWK_NEW=$(
|
AWK_NEW=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include src/awk/new.awk
|
@@include awk/new.awk
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
export AWK_NEW
|
export AWK_NEW
|
||||||
|
|
||||||
AWK_UPDATE=$(
|
AWK_UPDATE=$(
|
||||||
cat <<'EOF'
|
cat <<'EOF'
|
||||||
@@include src/awk/update.awk
|
@@include awk/update.awk
|
||||||
EOF
|
EOF
|
||||||
)
|
)
|
||||||
export AWK_UPDATE
|
export AWK_UPDATE
|
||||||
@@ -204,7 +204,7 @@ fi
|
|||||||
# Generate new entry
|
# Generate new entry
|
||||||
if [ "${1:-}" = "--new" ]; then
|
if [ "${1:-}" = "--new" ]; then
|
||||||
shift
|
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=""
|
file=""
|
||||||
while [ -f "$file" ] || [ -z "$file" ]; do
|
while [ -f "$file" ] || [ -z "$file" ]; do
|
||||||
uuid=$($UUIDGEN)
|
uuid=$($UUIDGEN)
|
||||||
|
|||||||
Reference in New Issue
Block a user