From 2a74eb4c3393ed699624cc877bdc5c1429f40d81 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 23 Jun 2025 18:51:20 +0200 Subject: [PATCH] feat(notes): list notes for opening, removing --- ayo.sh | 11 ++++++++++ notes.sh | 62 +++++++++++++++++++++++++++++++++++++++++++++++--------- 2 files changed, 63 insertions(+), 10 deletions(-) diff --git a/ayo.sh b/ayo.sh index cfcaf59..d8862fc 100755 --- a/ayo.sh +++ b/ayo.sh @@ -9,9 +9,20 @@ case $1 in jt) # journal using typora . ${HOME}/Projects/scripts/journal.sh -t $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 + ;; + no) # Notes open + . ${HOME}/Projects/scripts/notes.sh open $2 $3 $4 $5 $6 $7 $8 $9 + ;; + nr) # Notes remove + . ${HOME}/Projects/scripts/notes.sh remove $2 $3 $4 $5 $6 $7 $8 $9 + ;; nt) # Notes using typora . ${HOME}/Projects/scripts/notes.sh -t $2 $3 $4 $5 $6 $7 $8 $9 ;; + gs) # git status . ${HOME}/Projects/scripts/git.sh stat $2 $3 $4 $5 $6 $7 $8 $9 ;; diff --git a/notes.sh b/notes.sh index 96ac9b5..7af9a04 100755 --- a/notes.sh +++ b/notes.sh @@ -12,6 +12,19 @@ command=$1 getopts "t" typora; #check if -t flag is given +function editFile() { + notesSync + + # Open in editor + if [ "$typora" = "t" ]; then + typora "$1" + else + vim "$1" + fi + + notesSync +} + function createNote() { { read -p "Enter file name: " title @@ -28,22 +41,51 @@ function createNote() { echo $date_heading >> "$full_path" fi - # Open in editor - if [ "$typora" = "t" ]; then - typora "$full_path" - else - vim "$full_path" - fi + editFile "$full_path" } || { echo ">>> New note failed" } } -if [ "$1" = "list" ]; then - find $notes_dir -maxdepth 1 -type f -not -name '*~' -not -name '.gitignore' -printf '%f\n' +if [ "$1" = "list" ] || [ "$1" = "l" ]; then + files=( $notes_dir/*.md ) + index=0 + for file in "${files[@]##*/}"; do + ((index++)) + echo "$index) $file" + done +elif [ "$1" = "open" ] || [ "$1" = "o" ]; then + files=( $notes_dir/*.md ) + PS3="Open file #: " + echo "Please select a file." + COLUMNS=0; select file in "${files[@]##*/}"; do + { + echo "Opening $file" + editFile "$file" + break + } || + { + echo "bad choice" + break + } + done +elif [ "$1" = "remove" ] || [ "$1" = "rm" ]; then + files=( $notes_dir/*.md ) + PS3="Remove file #: " + echo "Please select a file." + COLUMNS=0; select file in "${files[@]##*/}"; do + { + echo "Removing $file" + rm "${notes_dir}/${file}" + notesSync + break + } || + { + echo "bad choice" + break + } + done else - notesSync createNote fi -notesSync