From ee8e6994f384dfc7d2a8aa0726dc7fcbd2437153 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=84min=20Baumeler?= Date: Fri, 23 May 2025 14:57:03 +0200 Subject: [PATCH] one temp file less --- fzf-vjour | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/fzf-vjour b/fzf-vjour index 6fb8d7d..e2f977f 100755 --- a/fzf-vjour +++ b/fzf-vjour @@ -387,10 +387,6 @@ __date_to_expression() { # @param string: Maximum length of filenames (for padding purposes) __filepath_to_searchline() { filepath="$1" - maxlen="$2" - totallen=$((maxlen + ${#ROOT} + COLLECTION_NAME_MAX_LEN + 2)) - #filepathpad=$(printf "%-${totallen}s" "$filepath") - filepathpad=$(dirname "$filepath")/$(printf "%-${maxlen}s" "$(basename "$filepath")") collection=$(dirname "$filepath" | sed "s|^$ROOT/*||") filename=$(basename "$filepath") @@ -404,7 +400,10 @@ __filepath_to_searchline() { # Parse file summary=$(grep '^SUMMARY:' "$filepath" | cut -d ':' -f 2 | sed 's/\\,/,/g') categories=$(grep '^CATEGORIES:' "$filepath" | cut -d ':' -f 2) - dtstamp=$(grep '^DTSTAMP:' "$filepath" | cut -d ':' -f 2) + dtstamp=$(grep '^LAST-MODIFIED:' "$filepath" | cut -d ':' -f 2) + if [ -z "$dtstamp" ]; then + dtstamp=$(grep '^DTSTAMP:' "$filepath" | cut -d ':' -f 2) + fi dtstart=$(grep '^DTSTART' "$filepath" | grep -oE '[0-9]{8}') due=$(grep '^DUE' "$filepath" | grep -oE '[0-9]{8}') priority=$(grep '^PRIORITY:' "$filepath" | cut -d ':' -f 2) @@ -458,20 +457,10 @@ __filepath_to_searchline() { } __lines() { - # Collect all files - FILES_TMP=$(mktemp) - find "$ROOT" -type f -name '*.ics' >"$FILES_TMP" - - # Compute max length of basenames - maxlen=0 - while IFS= read -r file; do - name=$(basename "$file") - [ ${#name} -gt "$maxlen" ] && maxlen=${#name} - done <"$FILES_TMP" - - lines=$(while IFS= read -r file; do - __filepath_to_searchline "$file" "$maxlen" - done <"$FILES_TMP") + lines=$(find "$ROOT" -type f -name '*.ics' | + while IFS= read -r file; do + __filepath_to_searchline "$file" + done) # Decorate lines=$(echo "$lines" | eval "$SED_COLLECTIONNAMES_TO_LABELS") @@ -479,7 +468,6 @@ __lines() { # Sort and cut off irreleant part lines=$(echo "$lines" | sort -g -r | cut -d ':' -f 2-) - rm "$FILES_TMP" echo "$lines" }