From 6f268c05cd4f965119b573196b3374a1990c6ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Thu, 5 Jun 2025 00:17:08 +0200 Subject: [PATCH] use whitespace free paths only --- src/awk/list.awk | 24 +++++++++++++++++------- src/main.sh | 26 ++++++++++++++------------ 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/awk/list.awk b/src/awk/list.awk index cdb7101..0a05324 100644 --- a/src/awk/list.awk +++ b/src/awk/list.awk @@ -130,6 +130,21 @@ ENDFILE { if (!type) { exit } + # Construct path, and check for validity + depth = split(FILENAME, path, "/"); + fpath = path[depth-1] "/" path[depth] + if (index(fpath, " ")) + { + print 10, + "-", + "-", + RED "ERROR: file '" fpath "' contains whitespaces!" OFF + exit + } + # Collection name + collection = path[depth-1] + collection = collection in collection2label ? collection2label[collection] : collection; + # Process content lines storetext_line(content_line, c, "CATEGORIES" ); storetext_line(content_line, c, "DESCRIPTION" ); @@ -160,11 +175,6 @@ ENDFILE { # format mod = c["LAST-MODIFIED"] ? c["LAST-MODIFIED"] : c["DTSTAMP"]; - # Collection name - depth = split(FILENAME, path, "/"); - collection = depth > 1 ? path[depth-1] : ""; - collection = collection in collection2label ? collection2label[collection] : collection; - # Date field. For VTODO entries, we show the due date, for journal entries, # the associated date. datecolor = CYAN; @@ -206,10 +216,10 @@ ENDFILE { print prio, mod, + fpath, collection, datecolor d OFF, flag, priotext summarycolor summary OFF, - WHITE categories OFF, - " " FAINT FILENAME OFF; + WHITE categories OFF; } diff --git a/src/main.sh b/src/main.sh index 9974bb5..6b286c6 100644 --- a/src/main.sh +++ b/src/main.sh @@ -105,12 +105,7 @@ __lines() { -v flag_journal="📘" \ -v flag_note="🗒️" \ "$AWK_LIST" | - sort -g -r | - cut -d ' ' -f 3- -} - -__filepath_from_selection() { - echo "$1" | grep -o ' \{50\}.*$' | xargs + sort -g -r } # Program starts here @@ -142,14 +137,16 @@ fi # Command line arguments to be self-contained # Generate preview of file from selection if [ "${1:-}" = "--preview" ]; then - file=$(__filepath_from_selection "$2") + name=$(echo "$2" | cut -d ' ' -f 3) + file="$ROOT/$name" awk -v field="DESCRIPTION" "$AWK_GET" "$file" | $CAT exit fi # Delete file from selection if [ "${1:-}" = "--delete" ]; then - file=$(__filepath_from_selection "$2") + name=$(echo "$2" | cut -d ' ' -f 3) + 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 @@ -199,21 +196,24 @@ if [ "${1:-}" = "--new" ]; then fi # Toggle completed flag if [ "${1:-}" = "--toggle-completed" ]; then - file=$(__filepath_from_selection "$2") + name=$(echo "$2" | cut -d ' ' -f 3) + file="$ROOT/$name" tmpfile=$(mktemp) awk "$AWK_ALTERTODO" "$file" >"$tmpfile" mv "$tmpfile" "$file" fi # Increase priority if [ "${1:-}" = "--increase-priority" ]; then - file=$(__filepath_from_selection "$2") + name=$(echo "$2" | cut -d ' ' -f 3) + file="$ROOT/$name" tmpfile=$(mktemp) awk -v delta="1" "$AWK_ALTERTODO" "$file" >"$tmpfile" mv "$tmpfile" "$file" fi # Decrease priority if [ "${1:-}" = "--decrease-priority" ]; then - file=$(__filepath_from_selection "$2") + name=$(echo "$2" | cut -d ' ' -f 3) + file="$ROOT/$name" tmpfile=$(mktemp) awk -v delta="-1" "$AWK_ALTERTODO" "$file" >"$tmpfile" mv "$tmpfile" "$file" @@ -257,6 +257,8 @@ selection=$( --no-sort \ --no-hscroll \ --ellipsis='' \ + --with-nth=4.. \ + --accept-nth=3 \ --preview="$0 --preview {}" \ --bind="ctrl-r:reload-sync($0 --reload)" \ --bind="ctrl-alt-d:become($0 --delete {})" \ @@ -274,7 +276,7 @@ if [ -z "$selection" ]; then return 0 fi -file=$(__filepath_from_selection "$selection") +file="$ROOT/$selection" if [ ! -f "$file" ]; then echo "ERROR: File '$file' does not exist!" >/dev/tty