one temp file less

This commit is contained in:
2025-05-23 14:57:03 +02:00
parent 2df8fcf1bc
commit ee8e6994f3

View File

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