inital commit

This commit is contained in:
Tristan Ancelet 2023-06-10 22:21:20 -05:00
commit 9616b56f53
3 changed files with 96 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*
!*.sh
!.gitignore

61
make_new.sh Executable file
View File

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

32
update_index.sh Executable file
View File

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