commit 9616b56f5397c9864646dce63aca864971f3fe5a Author: Tristan Ancelet Date: Sat Jun 10 22:21:20 2023 -0500 inital commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fb055a4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +* +!*.sh +!.gitignore diff --git a/make_new.sh b/make_new.sh new file mode 100755 index 0000000..8405b0a --- /dev/null +++ b/make_new.sh @@ -0,0 +1,61 @@ +#!/usr/bin/bash + +JOURNAL_DIR=/home/tristan/Journal +UPDATE_INDEX=$JOURNAL_DIR/update_index.sh +DATE=`date +'%Y-%m-%d'` +FILE="$DATE.wiki" + +# Getting the last journal entry file +LAST_JOURNAL_ENTRY=`ls $JOURNAL_DIR/*.wiki -1 | sort -n | tail -n 1` +# Getting just the filename +LAST_JOURNAL_ENTRY=`basename $LAST_JOURNAL_ENTRY` + +# Updating my index notes +[[ -f $UPDATE_INDEX ]] && $UPDATE_INDEX + +declare -A topics + +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?"; exit 1; } + + # 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 + +# 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 diff --git a/update_index.sh b/update_index.sh new file mode 100755 index 0000000..0c69f56 --- /dev/null +++ b/update_index.sh @@ -0,0 +1,32 @@ +#!/usr/bin/bash + +#set -x + +JOURNAL_DIR=/home/tristan/Journal +JOURNAL_INDEX=$JOURNAL_DIR/index.wiki + +declare -A topics + +for file in $JOURNAL_DIR/*.wiki; do + if [[ -f $file ]]; then + while read topic; do + [[ "$topic" == "" ]] && continue + base=`basename $file` + topics+=( ["$topic"]="$base" ) + # Remember == .* == is reserved for times of entry + done <<< "$( grep -Eo '= .^ =|=== .* ===' $file | tr '=' ' ' )" + fi +done + +echo "%title Journal Index + +" > $JOURNAL_INDEX + +printf -v topic_string '%s\n' "${!topics[@]}" + +# Since the hash-table will auto sort things +while read topic; do + [[ "$topic" == "" ]] && continue + file="${topics["$topic"]}" + echo "[[$file#$topic|$topic]]" >> $JOURNAL_INDEX +done <<< "$( sort -i <<< "$topic_string" )"