feat(notes): list subcommand
This commit is contained in:
parent
864bc2840c
commit
ec80a63e7a
1 changed files with 30 additions and 22 deletions
52
notes.sh
52
notes.sh
|
@ -12,30 +12,38 @@ command=$1
|
||||||
|
|
||||||
getopts "t" typora; #check if -t flag is given
|
getopts "t" typora; #check if -t flag is given
|
||||||
|
|
||||||
notesSync
|
function createNote() {
|
||||||
{
|
{
|
||||||
read -p "Enter file name: " title
|
read -p "Enter file name: " title
|
||||||
file_name=$title.md
|
file_name=$title.md
|
||||||
full_path="${notes_dir}/${file_name}"
|
full_path="${notes_dir}/${file_name}"
|
||||||
|
|
||||||
# IF Not Exists: create file & echo date
|
# IF Not Exists: create file & echo date
|
||||||
if ! test -f "$full_path"; then
|
if ! test -f "$full_path"; then
|
||||||
install -Dv /dev/null "$full_path"
|
install -Dv /dev/null "$full_path"
|
||||||
# TODO: update to correct heading from old entries
|
# TODO: update to correct heading from old entries
|
||||||
heading="# $title"
|
heading="# $title"
|
||||||
echo $heading > "$full_path"
|
echo $heading > "$full_path"
|
||||||
date_heading=$(date +'%b %d, %Y, %a %r')
|
date_heading=$(date +'%b %d, %Y, %a %r')
|
||||||
echo $date_heading >> "$full_path"
|
echo $date_heading >> "$full_path"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Open in editor
|
# Open in editor
|
||||||
if [ "$typora" = "t" ]; then
|
if [ "$typora" = "t" ]; then
|
||||||
typora "$full_path"
|
typora "$full_path"
|
||||||
else
|
else
|
||||||
vim "$full_path"
|
vim "$full_path"
|
||||||
fi
|
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
|
notesSync
|
||||||
|
|
Loading…
Reference in a new issue