feat(notes): provide note title as arg
This commit is contained in:
parent
6b69de9dec
commit
81889f62e0
1 changed files with 11 additions and 5 deletions
16
notes.sh
16
notes.sh
|
|
@ -22,7 +22,11 @@ function editFile() {
|
||||||
|
|
||||||
function createNote() {
|
function createNote() {
|
||||||
{
|
{
|
||||||
read -p "Create new note: " title
|
if [ "$1" = "" ]; then
|
||||||
|
read -p "Create new note: " title
|
||||||
|
else
|
||||||
|
title="${@:1}"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ "$title" = "" ]; then
|
if [ "$title" = "" ]; then
|
||||||
echo "Title cannot be empty."
|
echo "Title cannot be empty."
|
||||||
|
|
@ -30,19 +34,21 @@ function createNote() {
|
||||||
fi;
|
fi;
|
||||||
|
|
||||||
file_date="$(date +'%Y.%m.%d')"
|
file_date="$(date +'%Y.%m.%d')"
|
||||||
file_name=$title.md
|
file_name="$title.md"
|
||||||
full_path="${notes_dir}/${file_date}-${file_name}"
|
full_path="${notes_dir}/${file_date}-${file_name}"
|
||||||
|
|
||||||
# IF Not Exists: create file & echo date
|
# IF Not Exists: create file with:
|
||||||
|
# - title
|
||||||
|
# - date & time
|
||||||
if ! test -f "$full_path"; then
|
if ! test -f "$full_path"; then
|
||||||
install -Dv /dev/null "$full_path" >/dev/null
|
install -Dv /dev/null "$full_path" >/dev/null
|
||||||
# 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
|
||||||
|
|
||||||
|
# Edit the new / existing file
|
||||||
editFile "$full_path"
|
editFile "$full_path"
|
||||||
|
|
||||||
} || {
|
} || {
|
||||||
|
|
@ -138,7 +144,7 @@ function main() {
|
||||||
|
|
||||||
# DEFAULT: Default action - create new note
|
# DEFAULT: Default action - create new note
|
||||||
*)
|
*)
|
||||||
createNote
|
createNote $2
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue