From d219cee89a065646d7cfeb098870ea92eb6f6899 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 23 Jun 2025 20:05:45 +0200 Subject: [PATCH] feat: new tasks management & passing args to no & nr --- ayo.sh | 20 +++++++- example.config | 3 +- functions.sh | 11 +++++ notes.sh | 80 ++++++++++++++++++++------------ tasks.sh | 121 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 204 insertions(+), 31 deletions(-) create mode 100755 tasks.sh diff --git a/ayo.sh b/ayo.sh index d8862fc..f4a4a7e 100755 --- a/ayo.sh +++ b/ayo.sh @@ -10,6 +10,19 @@ case $1 in . ${HOME}/Projects/scripts/journal.sh -t $2 $3 $4 $5 $6 $7 $8 $9 ;; + tl) # Tasks list + . ${HOME}/Projects/scripts/tasks.sh list $2 $3 $4 $5 $6 $7 $8 $9 + ;; + to) # Tasks open + . ${HOME}/Projects/scripts/tasks.sh open $2 $3 $4 $5 $6 $7 $8 $9 + ;; + tr) # Tasks remove + . ${HOME}/Projects/scripts/tasks.sh remove $2 $3 $4 $5 $6 $7 $8 $9 + ;; + td) # Tasks mark as done + . ${HOME}/Projects/scripts/tasks.sh done $2 $3 $4 $5 $6 $7 $8 $9 + ;; + nl) # Notes list . ${HOME}/Projects/scripts/notes.sh list $2 $3 $4 $5 $6 $7 $8 $9 ;; @@ -38,6 +51,9 @@ case $1 in n | notes) . ${HOME}/Projects/scripts/notes.sh $2 $3 $4 $5 $6 $7 $8 $9 ;; + t | tasks) + . ${HOME}/Projects/scripts/tasks.sh $2 $3 $4 $5 $6 $7 $8 $9 + ;; j | journal) . ${HOME}/Projects/scripts/journal.sh $2 $3 $4 $5 $6 $7 $8 $9 ;; @@ -45,9 +61,9 @@ case $1 in echo 'Config script in-progress' ;; m | mac) - quickemu --vm macos-monterey.conf --width 1920 --height 1080 + quickemu --vm ${HOME}/macos-monterey.conf --width 1920 --height 1080 ;; ms) - quickemu --vm macos-monterey.conf --kill + quickemu --vm ${HOME}/macos-monterey.conf --kill ;; esac diff --git a/example.config b/example.config index 09aa4c0..820d54c 100644 --- a/example.config +++ b/example.config @@ -1,2 +1,3 @@ -notes_dir="${HOME}/notes/Journal" +notes_dir="${HOME}/notes" +tasks_dir="${HOME}/notes/tasks" scripts_dir="${HOME}/Projects/scripts" diff --git a/functions.sh b/functions.sh index 99ee889..2e1d01c 100644 --- a/functions.sh +++ b/functions.sh @@ -19,3 +19,14 @@ notesSync() { } fi } + + +yes_or_no() { + while true; do + read -p "$* [y/n]: " yn + case $yn in + [Yy]*) return 0 ;; + [Nn]*) return 1 ;; + esac + done +} diff --git a/notes.sh b/notes.sh index bafd930..86edb52 100755 --- a/notes.sh +++ b/notes.sh @@ -48,6 +48,8 @@ function createNote() { } } + +## LIST notes in directory if [ "$1" = "list" ] || [ "$1" = "l" ]; then files=( $notes_dir/*.md ) index=0 @@ -56,39 +58,61 @@ if [ "$1" = "list" ] || [ "$1" = "l" ]; then ((index++)) echo "$index) $file" done + +## OPEN a note from a list elif [ "$1" = "open" ] || [ "$1" = "o" ]; then files=( $notes_dir/*.md ) - PS3="Open file #: " - echo "Please select a file to OPEN." - notesSync - select file in "${files[@]##*/}"; do - { - echo "Opening $file" - editFile "$file" - break - } || - { - echo "bad choice" - break - } - done + + if ! [ "$2" = "" ]; then + index=($2-1) + open_file=${files[$index]} + editFile "$open_file" + notesSync + else + PS3="Open file #: " + echo "Please select a file to OPEN." + notesSync + select file in "${files[@]##*/}"; do + { + echo "Opening $file" + editFile "$file" + break + } || + { + echo "bad choice" + break + } + done + fi + +## REMOVE a note from a list elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then files=( $notes_dir/*.md ) - PS3="Remove file #: " - echo "Please select a file to REMOVE." notesSync - select file in "${files[@]##*/}"; do - { - echo "Removing $file" - rm "${notes_dir}/${file}" - notesSync - break - } || - { - echo "bad choice" - break - } - done + + if ! [ "$2" = "" ]; then + index=($2-1) + remove_file=${files[$index]} + echo "Removing $remove_file" + rm "$remove_file" + notesSync + else + PS3="Remove file #: " + echo "Please select a file to REMOVE." + select file in "${files[@]##*/}"; do + { + echo "Removing $file" + rm "${notes_dir}/${file}" + notesSync + break + } || + { + echo "bad choice" + break + } + done + fi +## CREATE a note (default) else createNote fi diff --git a/tasks.sh b/tasks.sh new file mode 100755 index 0000000..dac4c7c --- /dev/null +++ b/tasks.sh @@ -0,0 +1,121 @@ +#! /usr/bin/bash + +## tasks management + +# Load config +. ${HOME}/ayo.conf +. ${scripts_dir}/functions.sh + +# TODO: write log for echoes with >>> + +command=$1 + +getopts "t" typora; #check if -t flag is given +echo ">>> typora? $typora" + +function editFile() { + notesSync + + edit_file="${tasks_dir}/$1" + # Open in editor + if [ "$typora" = "t" ]; then + typora "$edit_file" + else + vim "$edit_file" + fi + + notesSync +} + +function createTask() { + { + read -p "Create new task: " title + file_name=$title.md + full_path="${tasks_dir}/${file_name}" + + # IF Not Exists: create file & echo date + if ! test -f "$full_path"; then + install -Dv /dev/null "$full_path" + # TODO: update to correct heading from old entries + heading="# $title" + echo $heading > "$full_path" + date_heading=$(date +'%b %d, %Y, %a %r') + echo $date_heading >> "$full_path" + fi + editFile "$full_path" + + } || { + echo ">>> New note failed" + } +} + + +## LIST tasks in directory +if [ "$1" = "list" ] || [ "$1" = "l" ]; then + files=( $tasks_dir/*.md ) + index=0 + notesSync + for file in "${files[@]##*/}"; do + ((index++)) + echo "$index) $file" + done + +## OPEN a note from a list +elif [ "$1" = "open" ] || [ "$1" = "o" ]; then + files=( $tasks_dir/*.md ) + PS3="Open file #: " + echo "Please select a file to OPEN." + notesSync + select file in "${files[@]##*/}"; do + { + editFile "$file" + break + } || + { + echo "bad choice" + break + } + done + +## MARK AS DONE a note from a list +elif [ "$1" = "done" ] || [ "$1" = "d" ]; then + files=( $tasks_dir/*.md ) + PS3="Mark as Done, file #: " + echo "Please select a file to MARK AS DONE." + notesSync + select file in "${files[@]##*/}"; do + { + mv "${tasks_dir}/${file}" "${tasks_dir}/done" + notesSync + break + } || + { + echo "bad choice" + break + } + done + + +## REMOVE a note from a list +elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then + files=( $tasks_dir/*.md ) + PS3="Remove file #: " + echo "Please select a file to REMOVE." + notesSync + select file in "${files[@]##*/}"; do + { + echo "Removing $file" + rm "${tasks_dir}/${file}" + notesSync + break + } || + { + echo "bad choice" + break + } + done + +## CREATE a note (default) +else + createTask +fi