From ec80a63e7a49d3dd44c8438824695244461493e2 Mon Sep 17 00:00:00 2001 From: Ayo Date: Mon, 23 Jun 2025 18:07:36 +0200 Subject: [PATCH] feat(notes): list subcommand --- notes.sh | 52 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/notes.sh b/notes.sh index 0558670..96ac9b5 100755 --- a/notes.sh +++ b/notes.sh @@ -12,30 +12,38 @@ command=$1 getopts "t" typora; #check if -t flag is given -notesSync -{ - read -p "Enter file name: " title - file_name=$title.md - full_path="${notes_dir}/${file_name}" +function createNote() { + { + read -p "Enter file name: " title + file_name=$title.md + full_path="${notes_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 + # 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 - # Open in editor - if [ "$typora" = "t" ]; then - typora "$full_path" - else - vim "$full_path" - fi + # Open in editor + if [ "$typora" = "t" ]; then + typora "$full_path" + else + vim "$full_path" + fi -} || { - echo ">>> New note failed" + } || { + echo ">>> New note failed" + } } + +if [ "$1" = "list" ]; then + find $notes_dir -maxdepth 1 -type f -not -name '*~' -not -name '.gitignore' -printf '%f\n' +else + notesSync + createNote +fi notesSync