From 4759318d299ade0b7c682975b7a8c8aede7fb7af Mon Sep 17 00:00:00 2001 From: Tristan Ancelet Date: Fri, 8 Dec 2023 12:07:31 -0600 Subject: [PATCH] Had to update path-names to allow scripts to access the files after update to journals.sh --- scripts/make_new.sh | 30 ++++++++++++++++-------------- scripts/update_all.sh | 15 +++++++-------- scripts/update_full_index.sh | 22 +++++++++++----------- scripts/update_index.sh | 26 ++++++++++++-------------- scripts/update_tasks.py | 13 ++++++++----- scripts/utils/get-task.sh | 2 +- scripts/utils/journals.sh | 16 +++++++++++++--- scripts/utils/tasks.sh | 4 ++-- scripts/utils/topics.sh | 4 ++-- 9 files changed, 72 insertions(+), 60 deletions(-) diff --git a/scripts/make_new.sh b/scripts/make_new.sh index ac4275e..602bedc 100755 --- a/scripts/make_new.sh +++ b/scripts/make_new.sh @@ -1,17 +1,16 @@ -#!/usr/bin/bash +#!/opt/homebrew/bin/bash -JOURNAL_DIR=~/Journal cd $JOURNAL_DIR -UPDATE_ALL=$JOURNAL_DIR/scripts/update_all.sh DATE=`date +'%Y-%m-%d'` FILE="$JOURNAL_DIR/$DATE.wiki" -[[ -f $JOURNAL_DIR/scripts/utils/journals.sh ]] && . $JOURNAL_DIR/scripts/utils/journals.sh +[[ -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 @@ -39,28 +38,31 @@ echo "[[$LAST_JOURNAL_ENTRY|Last Journal Entry]] %title $DATE Journal Entry -# Main Topics from previous 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]]"; + [[ $level -eq 1 ]] && echo "- [[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; done ) -# Times +Times +----- $( for topic in "${!topics[@]}"; do level=${topics["$topic"]} - [[ $level -eq 2 ]] && echo "[[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; + [[ $level -eq 2 ]] && echo "- [[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; done ) -# Subtopics +Subtopics +--------- $( for topic in "${!topics[@]}"; do level=${topics["$topic"]} - [[ $level -gt 2 ]] && echo "[[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; + [[ $level -gt 2 ]] && echo "- [[$LAST_JOURNAL_ENTRY#$topic|$topic]]"; done ) " > $FILE - - - -[[ -f $UPDATE_ALL ]] && $UPDATE_ALL diff --git a/scripts/update_all.sh b/scripts/update_all.sh index 1cf3964..32c66c2 100755 --- a/scripts/update_all.sh +++ b/scripts/update_all.sh @@ -1,12 +1,11 @@ -#!/usr/bin/bash -JOURNAL_DIR=~/Journal -FILES_DIR=$JOURNAL_DIR/files -SCRIPT_DIR=$JOURNAL_DIR/scripts/enabled +#!/opt/homebrew/bin/bash +export PROJ_DIR=~/Notes +export JOURNAL_DIR=$PROJ_DIR/wikis +export FILES_DIR=$PROJ_DIR/files +export SCRIPT_DIR=$PROJ_DIR/scripts -#set -x +cd $PROJ_DIR -cd $JOURNAL_DIR - -for script in $SCRIPT_DIR/*; do +for script in $SCRIPT_DIR/enabled/**; do [[ -x $script ]] && $script done diff --git a/scripts/update_full_index.sh b/scripts/update_full_index.sh index f4a94a5..63d50f1 100755 --- a/scripts/update_full_index.sh +++ b/scripts/update_full_index.sh @@ -1,11 +1,9 @@ -#!/usr/bin/bash +#!/opt/homebrew/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 +[[ -f $SCRIPT_DIR/utils/journals.sh ]] && . $SCRIPT_DIR/utils/journals.sh +JOURNAL_FULL_INDEX=$PROJ_DIR/full_index.wiki declare -a journals get_journals journals @@ -15,21 +13,23 @@ echo " # Journals: Times & Topics $( -for file in ${journals[@]}; do +for file_path in ${journals[@]}; do + file="${file_path/*\/}" + journal_full_path=$PROJ_DIR$file_path echo -e '\n\n' - echo "[[$file|$(echo $file | cut -d '.' -f 1 | tr '-' ' ')]]" + echo "[[$file_path|$(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 " - [[$file_path#$time|$time]]" + done <<< "$( grep '== ' $journal_full_path | 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)" + echo " - [[$file_path#$topic|$topic]]" + done <<< "$( grep -Eo '^===[=]* .+ ===[=]*' $journal_full_path | tr '=' ' ' | sort -u)" done ) diff --git a/scripts/update_index.sh b/scripts/update_index.sh index b6174c4..5b5528e 100755 --- a/scripts/update_index.sh +++ b/scripts/update_index.sh @@ -1,26 +1,24 @@ -#!/usr/bin/bash +#!/opt/homebrew/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 +[[ -f $SCRIPT_DIR/utils/journals.sh ]] && . $SCRIPT_DIR/utils/journals.sh +JOURNAL_INDEX=$PROJ_DIR/index.wiki declare -a journals get_journals journals echo " %title Journal Index -[[full_index.wiki|Full Index]] -[[tasks.wiki|Tasks Index]] -[[how-to.wiki|How-To Index]] +----------------------------------------------- +[[/index.wiki|Index]] [[full_index.wiki|Full Index]] [[tasks.wiki|Tasks Index]] [[how-to.wiki|How-To Index]] +----------------------------------------------- -# Journals +Journals +-------- $( -for journal in ${journals[@]}; do - echo "- [[$journal|$( echo $journal | cut -d'.' -f 1 | tr '-' ' ')]]" +for journal_path in ${journals[@]}; do + journal_file="${journal_path/*\/}" + journal_name="$( echo $journal_file | cut -d '.' -f 1 | tr '-' '/' )" + echo "- [[$journal_path|$journal_name]]" done ) diff --git a/scripts/update_tasks.py b/scripts/update_tasks.py index 9497270..4f1e011 100755 --- a/scripts/update_tasks.py +++ b/scripts/update_tasks.py @@ -2,10 +2,10 @@ from pathlib import Path from utils.py.journals import * +import os -SCRIPT_DIR=Path.home()/"Journal"/"scripts" -SCRIPT_DIR.cwd() -TASK_FILE=Path.home()/"Journal"/"tasks.wiki" +PROJ_DIR=Path(os.getenv("PROJ_DIR")) +TASK_FILE=PROJ_DIR/"tasks.wiki" if not TASK_FILE.exists(): TASK_FILE.touch() @@ -27,14 +27,17 @@ with TASK_FILE.open('a') as file: file.write(f"[[{filename}|{file_date}]]\n") if len(todo) != 0: - file.write("# TODO\n") + file.write("TODO\n") + file.write("----\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") + file.write("DONE\n") + file.write("----\n") for task in done: task_string=task.replace('=','').strip() file.write(f"- [[{filename}#{task_string}|{task_string}]]\n") diff --git a/scripts/utils/get-task.sh b/scripts/utils/get-task.sh index 7259e0f..80ea074 100644 --- a/scripts/utils/get-task.sh +++ b/scripts/utils/get-task.sh @@ -1,4 +1,4 @@ -#!/usr/bin/bash +#!/opt/homebrew/bin/bash : " get_task_number This function will query sqlite db to either get the number of a task OR create the task and return the number diff --git a/scripts/utils/journals.sh b/scripts/utils/journals.sh index adc1c40..cf46f7f 100644 --- a/scripts/utils/journals.sh +++ b/scripts/utils/journals.sh @@ -1,8 +1,18 @@ -#!/usr/bin/bash +#!/opt/homebrew/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 ) ) + declare -n array="${1:?"get_journals : Variable not passed through"}" + array=( $( ls -1 $JOURNAL_DIR | grep -Eo $JOURNAL_REGEX | sort -n ) ) + + local file + for i in ${!array[@]}; do + file="${array[$i]}" + DIR=`basename $JOURNAL_DIR` + if [[ "$file" != $DIR/* ]]; then + file="/$DIR/$file" + array[$i]=$file + fi + done } diff --git a/scripts/utils/tasks.sh b/scripts/utils/tasks.sh index 9b2c350..a904fdc 100644 --- a/scripts/utils/tasks.sh +++ b/scripts/utils/tasks.sh @@ -1,5 +1,5 @@ -#!/usr/bin/bash -[[ -f ~/Journal/utils/journals.sh ]] && . ~/Journal/utils/journals.sh +#!/opt/homebrew/bin/bash +[[ -f ~/Notes/utils/journals.sh ]] && . ~/Notes/utils/journals.sh function get_tasks () { set -x diff --git a/scripts/utils/topics.sh b/scripts/utils/topics.sh index 51826cc..02aa9bf 100644 --- a/scripts/utils/topics.sh +++ b/scripts/utils/topics.sh @@ -1,5 +1,5 @@ -#!/usr/bin/bash -[[ -f ~/Journal/utils/journals.sh ]] && . ~/Journal/utils/journals.sh +#!/opt/homebrew/bin/bash +[[ -f ~/Notes/utils/journals.sh ]] && . ~/Notes/utils/journals.sh function get_tasks () { local -a journals