feat: new tasks management & passing args to no & nr

This commit is contained in:
Ayo Ayco 2025-06-23 20:05:45 +02:00
parent be3339941b
commit d219cee89a
5 changed files with 204 additions and 31 deletions

20
ayo.sh
View file

@ -10,6 +10,19 @@ case $1 in
. ${HOME}/Projects/scripts/journal.sh -t $2 $3 $4 $5 $6 $7 $8 $9 . ${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 nl) # Notes list
. ${HOME}/Projects/scripts/notes.sh list $2 $3 $4 $5 $6 $7 $8 $9 . ${HOME}/Projects/scripts/notes.sh list $2 $3 $4 $5 $6 $7 $8 $9
;; ;;
@ -38,6 +51,9 @@ case $1 in
n | notes) n | notes)
. ${HOME}/Projects/scripts/notes.sh $2 $3 $4 $5 $6 $7 $8 $9 . ${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) j | journal)
. ${HOME}/Projects/scripts/journal.sh $2 $3 $4 $5 $6 $7 $8 $9 . ${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' echo 'Config script in-progress'
;; ;;
m | mac) m | mac)
quickemu --vm macos-monterey.conf --width 1920 --height 1080 quickemu --vm ${HOME}/macos-monterey.conf --width 1920 --height 1080
;; ;;
ms) ms)
quickemu --vm macos-monterey.conf --kill quickemu --vm ${HOME}/macos-monterey.conf --kill
;; ;;
esac esac

View file

@ -1,2 +1,3 @@
notes_dir="${HOME}/notes/Journal" notes_dir="${HOME}/notes"
tasks_dir="${HOME}/notes/tasks"
scripts_dir="${HOME}/Projects/scripts" scripts_dir="${HOME}/Projects/scripts"

View file

@ -19,3 +19,14 @@ notesSync() {
} }
fi fi
} }
yes_or_no() {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) return 1 ;;
esac
done
}

View file

@ -48,6 +48,8 @@ function createNote() {
} }
} }
## LIST notes in directory
if [ "$1" = "list" ] || [ "$1" = "l" ]; then if [ "$1" = "list" ] || [ "$1" = "l" ]; then
files=( $notes_dir/*.md ) files=( $notes_dir/*.md )
index=0 index=0
@ -56,39 +58,61 @@ if [ "$1" = "list" ] || [ "$1" = "l" ]; then
((index++)) ((index++))
echo "$index) $file" echo "$index) $file"
done done
## OPEN a note from a list
elif [ "$1" = "open" ] || [ "$1" = "o" ]; then elif [ "$1" = "open" ] || [ "$1" = "o" ]; then
files=( $notes_dir/*.md ) files=( $notes_dir/*.md )
PS3="Open file #: "
echo "Please select a file to OPEN." if ! [ "$2" = "" ]; then
notesSync index=($2-1)
select file in "${files[@]##*/}"; do open_file=${files[$index]}
{ editFile "$open_file"
echo "Opening $file" notesSync
editFile "$file" else
break PS3="Open file #: "
} || echo "Please select a file to OPEN."
{ notesSync
echo "bad choice" select file in "${files[@]##*/}"; do
break {
} echo "Opening $file"
done editFile "$file"
break
} ||
{
echo "bad choice"
break
}
done
fi
## REMOVE a note from a list
elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then
files=( $notes_dir/*.md ) files=( $notes_dir/*.md )
PS3="Remove file #: "
echo "Please select a file to REMOVE."
notesSync notesSync
select file in "${files[@]##*/}"; do
{ if ! [ "$2" = "" ]; then
echo "Removing $file" index=($2-1)
rm "${notes_dir}/${file}" remove_file=${files[$index]}
notesSync echo "Removing $remove_file"
break rm "$remove_file"
} || notesSync
{ else
echo "bad choice" PS3="Remove file #: "
break echo "Please select a file to REMOVE."
} select file in "${files[@]##*/}"; do
done {
echo "Removing $file"
rm "${notes_dir}/${file}"
notesSync
break
} ||
{
echo "bad choice"
break
}
done
fi
## CREATE a note (default)
else else
createNote createNote
fi fi

121
tasks.sh Executable file
View file

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