#!/opt/homebrew/bin/bash cd $JOURNAL_DIR DATE=`date +'%Y-%m-%d'` FILE="$JOURNAL_DIR/$DATE.wiki" [[ -f $SCRIPT_DIR/utils/journals.sh ]] && . $SCRIPT_DIR/utils/journals.sh # Getting the last journal entry file declare -a journals get_journals journals LAST_JOURNAL_ENTRY="${journals[-1]}" LAST_JOURNAL_ENTRY="${LAST_JOURNAL_ENTRY/*\/}" declare -A topics [[ -f $file ]] && exit while read line; do # Stripping the '=' characters from the topic declare -i level=$( tr -cd '=' <<< "$line" | wc -c) [[ $level -eq 0 ]] && { echo "A line ($line) that was grabbed returned a 0 count level?"; continue; } # Getting the topic "level" by getting the number of = in the topic and dividing it by 2 # # LEVELS: # 1: Topic # 2: Times # 3->5: Subtopic during timeframe level=$(( $level / 2 )) topic="${line//=/}" topics+=( ["$topic"]=$level ) done <<< "$( grep -Eo '=+ .* =+' $LAST_JOURNAL_ENTRY )" [[ -f "$file" ]] && exit 0 echo "[[$LAST_JOURNAL_ENTRY|Last Journal Entry]] %title $DATE Journal Entry --------------------- [[/index.wiki|Index]] --------------------- Main Topics from previous journal entry --------------------------------------- $( for topic in "${!topics[@]}"; do level=${topics["$topic"]} [[ $level -eq 1 ]] && echo "- [[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; done ) Times ----- $( for topic in "${!topics[@]}"; do level=${topics["$topic"]} [[ $level -eq 2 ]] && echo "- [[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; done ) Subtopics --------- $( for topic in "${!topics[@]}"; do level=${topics["$topic"]} [[ $level -gt 2 ]] && echo "- [[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; done ) " > $FILE