From a27e7f561e8af875dc1f2d9f0fb8bf343846e90e Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Wed, 14 Jun 2023 14:15:13 -0500 Subject: [PATCH] restructured project --- .gitignore | 4 ++- scripts/enabled/update_full_index.sh | 1 + scripts/enabled/update_index.sh | 1 + scripts/enabled/update_tasks.py | 1 + make_new.sh => scripts/make_new.sh | 28 ++++++++++++-------- scripts/update_all.sh | 11 ++++++++ scripts/update_full_index.sh | 37 ++++++++++++++++++++++++++ scripts/update_index.sh | 25 ++++++++++++++++++ scripts/update_tasks.py | 39 ++++++++++++++++++++++++++++ scripts/utils/journals.sh | 8 ++++++ scripts/utils/tasks.sh | 26 +++++++++++++++++++ scripts/utils/topics.sh | 16 ++++++++++++ update_index.sh | 32 ----------------------- 13 files changed, 185 insertions(+), 44 deletions(-) create mode 120000 scripts/enabled/update_full_index.sh create mode 120000 scripts/enabled/update_index.sh create mode 120000 scripts/enabled/update_tasks.py rename make_new.sh => scripts/make_new.sh (78%) create mode 100755 scripts/update_all.sh create mode 100755 scripts/update_full_index.sh create mode 100755 scripts/update_index.sh create mode 100755 scripts/update_tasks.py create mode 100644 scripts/utils/journals.sh create mode 100644 scripts/utils/tasks.sh create mode 100644 scripts/utils/topics.sh delete mode 100755 update_index.sh diff --git a/.gitignore b/.gitignore index fb055a4..ea0fa40 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ * -!*.sh +!scripts +!scripts/* +!scripts/*/* !.gitignore diff --git a/scripts/enabled/update_full_index.sh b/scripts/enabled/update_full_index.sh new file mode 120000 index 0000000..93d745e --- /dev/null +++ b/scripts/enabled/update_full_index.sh @@ -0,0 +1 @@ +../update_full_index.sh \ No newline at end of file diff --git a/scripts/enabled/update_index.sh b/scripts/enabled/update_index.sh new file mode 120000 index 0000000..2a4b8c7 --- /dev/null +++ b/scripts/enabled/update_index.sh @@ -0,0 +1 @@ +../update_index.sh \ No newline at end of file diff --git a/scripts/enabled/update_tasks.py b/scripts/enabled/update_tasks.py new file mode 120000 index 0000000..27d8fb5 --- /dev/null +++ b/scripts/enabled/update_tasks.py @@ -0,0 +1 @@ +../update_tasks.py \ No newline at end of file diff --git a/make_new.sh b/scripts/make_new.sh similarity index 78% rename from make_new.sh rename to scripts/make_new.sh index 8405b0a..a7c9665 100755 --- a/make_new.sh +++ b/scripts/make_new.sh @@ -1,20 +1,23 @@ #!/usr/bin/bash -JOURNAL_DIR=/home/tristan/Journal -UPDATE_INDEX=$JOURNAL_DIR/update_index.sh + +JOURNAL_DIR=~/Journal +cd $JOURNAL_DIR +UPDATE_ALL=$JOURNAL_DIR/scripts/update_all.sh DATE=`date +'%Y-%m-%d'` -FILE="$DATE.wiki" +FILE="$JOURNAL_DIR/$DATE.wiki" + +[[ -f $JOURNAL_DIR/utils/journals.sh ]] && . $JOURNAL_DIR/utils/journals.sh # 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 journals +get_journals journals +LAST_JOURNAL_ENTRY="${journals[-1]}" declare -A topics +[[ -f $file ]] && exit + while read line; do # Stripping the '=' characters from the topic declare -i level=$( tr -cd '=' <<< "$line" | wc -c) @@ -44,14 +47,12 @@ $( for topic in "${!topics[@]}"; do 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]]"; @@ -59,3 +60,8 @@ done ) " > $FILE + + + + +[[ -f $UPDATE_ALL ]] && $UPDATE_ALL diff --git a/scripts/update_all.sh b/scripts/update_all.sh new file mode 100755 index 0000000..60784ac --- /dev/null +++ b/scripts/update_all.sh @@ -0,0 +1,11 @@ +#!/usr/bin/bash +JOURNAL_DIR=~/Journal +SCRIPT_DIR=$JOURNAL_DIR/scripts/enabled + +#set -x + +cd $JOURNAL_DIR + +for script in $SCRIPT_DIR/*; do + [[ -x $script ]] && $script +done diff --git a/scripts/update_full_index.sh b/scripts/update_full_index.sh new file mode 100755 index 0000000..f4a94a5 --- /dev/null +++ b/scripts/update_full_index.sh @@ -0,0 +1,37 @@ +#!/usr/bin/bash + +#set -x + +JOURNAL_DIR=~/Journal +JOURNAL_SCRIPT_DIR=$JOURNAL_DIR/scripts +[[ -f $JOURNAL_SCRIPT_DIR/utils/journals.sh ]] && . $JOURNAL_SCRIPT_DIR/utils/journals.sh +JOURNAL_FULL_INDEX=$JOURNAL_DIR/full_index.wiki + +declare -a journals +get_journals journals + +echo " +%title Full Index + +# Journals: Times & Topics +$( +for file in ${journals[@]}; do + echo -e '\n\n' + echo "[[$file|$(echo $file | cut -d '.' -f 1 | tr '-' ' ')]]" + + echo "# Times" + while read time; do + echo " - [[$file#$time|$time]]" + done <<< "$( grep '== ' $file | grep -Eo '[0-9]+:[0-9]+ [A-Za-z]{2} [A-Za-z]{3}')" + + echo + + echo "# Topics" + while read topic; do + echo " - [[$file#$topic|$topic]]" + done <<< "$( grep -Eo '^===[=]* .+ ===[=]*' $file | tr '=' ' ' | sort -u)" +done +) + + +" > $JOURNAL_FULL_INDEX diff --git a/scripts/update_index.sh b/scripts/update_index.sh new file mode 100755 index 0000000..29ed52e --- /dev/null +++ b/scripts/update_index.sh @@ -0,0 +1,25 @@ +#!/usr/bin/bash + +#set -x + +JOURNAL_DIR=/home/tristan/Journal +JOURNAL_SCRIPT_DIR=$JOURNAL_DIR/scripts +[[ -f $JOURNAL_SCRIPT_DIR/utils/journals.sh ]] && . $JOURNAL_SCRIPT_DIR/utils/journals.sh + +JOURNAL_INDEX=$JOURNAL_DIR/index.wiki + +declare -a journals +get_journals journals + +echo " +%title Journal Index +[[full_index.wiki|Full Index]] + +# Journals +$( +for journal in ${journals[@]}; do + echo "- [[$journal|$( echo $journal | cut -d'.' -f 1 | tr '-' ' ')]]" +done +) + +" > $JOURNAL_INDEX diff --git a/scripts/update_tasks.py b/scripts/update_tasks.py new file mode 100755 index 0000000..51f2825 --- /dev/null +++ b/scripts/update_tasks.py @@ -0,0 +1,39 @@ +#!/usr/bin/python3 + +from pathlib import Path +from utils.py.journals import * + +TASK_FILE=Path.home()/"Journal"/"tasks.wiki" + +if not TASK_FILE.exists(): + TASK_FILE.touch() +else: + # Clearing out the file + with TASK_FILE.open('w') as file: + file.write("") + + +with TASK_FILE.open('a') as file: + file.write("%title Tasks\n\n\n") + + for fileobj in get_journal(): + filename = fileobj.name + todo, done = get_task_lists(fileobj) + + if len(todo) != 0 or len(done) != 0: + file_date=filename.split('.')[0].replace('-',' ') + file.write(f"[[{filename}|{file_date}]]\n") + + if len(todo) != 0: + file.write("# TODO\n") + for task in todo: + task_string=task.replace('=','').strip() + file.write(f"- [[{filename}#{task_string}|{task_string}]]\n") + file.write("\n") + + if len(done) != 0: + file.write("# DONE\n") + for task in done: + task_string=task.replace('=','').strip() + file.write(f"- [[{filename}#{task_string}|{task_string}]]\n") + file.write("\n") diff --git a/scripts/utils/journals.sh b/scripts/utils/journals.sh new file mode 100644 index 0000000..adc1c40 --- /dev/null +++ b/scripts/utils/journals.sh @@ -0,0 +1,8 @@ +#!/usr/bin/bash + + +function get_journals () { + local JOURNAL_REGEX='[0-9]{4}-[0-9]{2}-[0-9]{2}.wiki' + [[ "$1" ]] && declare -n hashmap="$1" + hashmap=( $( ls $JOURNAL_DIR -1 | grep -Eo $JOURNAL_REGEX | sort -n ) ) +} diff --git a/scripts/utils/tasks.sh b/scripts/utils/tasks.sh new file mode 100644 index 0000000..9b2c350 --- /dev/null +++ b/scripts/utils/tasks.sh @@ -0,0 +1,26 @@ +#!/usr/bin/bash +[[ -f ~/Journal/utils/journals.sh ]] && . ~/Journal/utils/journals.sh + +function get_tasks () { + set -x + local -a journals + get_journals journals + + local TASK_REGEX='====[[:space:]]+.+[[:space:]]+====' + + declare -n TODO="$1" + declare -n DONE="$2" + + for journal in "${journals[@]}"; do + if grep -Eo $TASK_REGEX $journal >/dev/null 2>&1; then + + while read line; do + if [[ "$line" == *'(DUE: DONE)'* ]]; then + DONE["$journal"]="$( echo -e "${DONE["$journal"]}\n$line" )" + else + TODO["$journal"]="$( echo -e "${TODO["$journal"]}\n$line" )" + fi + done <<< "$( grep -Eo $TASK_REGEX $journal | tr '=' ' ')" + fi + done +} diff --git a/scripts/utils/topics.sh b/scripts/utils/topics.sh new file mode 100644 index 0000000..51826cc --- /dev/null +++ b/scripts/utils/topics.sh @@ -0,0 +1,16 @@ +#!/usr/bin/bash +[[ -f ~/Journal/utils/journals.sh ]] && . ~/Journal/utils/journals.sh + +function get_tasks () { + local -a journals + get_journals journals + local TOPIC_REGEX='^=== .+ ===' + + declare -n TOPICS="$1" + + for journal in "${journals[@]}"; do + if grep -E "$TOPIC_REGEX" $journal >/dev/null 2>&1; then + TOPICS["$journal"]="$( grep -Eo "$TOPIC_REGEX" $journal | tr '=' ' ' )" + fi + done +} diff --git a/update_index.sh b/update_index.sh deleted file mode 100755 index 0c69f56..0000000 --- a/update_index.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/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" )"