one temp file less
This commit is contained in:
28
fzf-vjour
28
fzf-vjour
@@ -387,10 +387,6 @@ __date_to_expression() {
|
|||||||
# @param string: Maximum length of filenames (for padding purposes)
|
# @param string: Maximum length of filenames (for padding purposes)
|
||||||
__filepath_to_searchline() {
|
__filepath_to_searchline() {
|
||||||
filepath="$1"
|
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/*||")
|
collection=$(dirname "$filepath" | sed "s|^$ROOT/*||")
|
||||||
filename=$(basename "$filepath")
|
filename=$(basename "$filepath")
|
||||||
|
|
||||||
@@ -404,7 +400,10 @@ __filepath_to_searchline() {
|
|||||||
# Parse file
|
# Parse file
|
||||||
summary=$(grep '^SUMMARY:' "$filepath" | cut -d ':' -f 2 | sed 's/\\,/,/g')
|
summary=$(grep '^SUMMARY:' "$filepath" | cut -d ':' -f 2 | sed 's/\\,/,/g')
|
||||||
categories=$(grep '^CATEGORIES:' "$filepath" | cut -d ':' -f 2)
|
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}')
|
dtstart=$(grep '^DTSTART' "$filepath" | grep -oE '[0-9]{8}')
|
||||||
due=$(grep '^DUE' "$filepath" | grep -oE '[0-9]{8}')
|
due=$(grep '^DUE' "$filepath" | grep -oE '[0-9]{8}')
|
||||||
priority=$(grep '^PRIORITY:' "$filepath" | cut -d ':' -f 2)
|
priority=$(grep '^PRIORITY:' "$filepath" | cut -d ':' -f 2)
|
||||||
@@ -458,20 +457,10 @@ __filepath_to_searchline() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
__lines() {
|
__lines() {
|
||||||
# Collect all files
|
lines=$(find "$ROOT" -type f -name '*.ics' |
|
||||||
FILES_TMP=$(mktemp)
|
while IFS= read -r file; do
|
||||||
find "$ROOT" -type f -name '*.ics' >"$FILES_TMP"
|
__filepath_to_searchline "$file"
|
||||||
|
done)
|
||||||
# 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")
|
|
||||||
|
|
||||||
# Decorate
|
# Decorate
|
||||||
lines=$(echo "$lines" | eval "$SED_COLLECTIONNAMES_TO_LABELS")
|
lines=$(echo "$lines" | eval "$SED_COLLECTIONNAMES_TO_LABELS")
|
||||||
@@ -479,7 +468,6 @@ __lines() {
|
|||||||
# Sort and cut off irreleant part
|
# Sort and cut off irreleant part
|
||||||
lines=$(echo "$lines" | sort -g -r | cut -d ':' -f 2-)
|
lines=$(echo "$lines" | sort -g -r | cut -d ':' -f 2-)
|
||||||
|
|
||||||
rm "$FILES_TMP"
|
|
||||||
echo "$lines"
|
echo "$lines"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user