Nice idea! Something a bit more elaborate (just for fun):
notes() {
if [ ! -z "$1" ]; then
# Using the "$@" here will take all parameters passed into
# this function so we can place everything into our file.
echo "$@" >> "$HOME/notes.md"
else
# If no arguments were passed we will take stdin and place
# it into our notes instead.
cat - >> "$HOME/notes.md"
fi
}
With this function we can use the heredoc syntax to write multi-line notes:
notes <<NOTE
This is a very long note
because sometimes I like
to write explanations of
my commands and such.
NOTE
Hi Jonathan, I just tried your code and I was suprised to find that when I call the notescommand without parameters, it doesn't show the content of the notes.md file. Instead it expects me to introduce the note content itself, and it doesn't write it to file till I do Ctrl + C. Hmm... I'll find out how to fix this.
That looks like it's the intended behaviour to make it easy to write multi-line notes. If you'd rather have it just show the notes, then change the second branch of the if statement to just cat "$HOME/notes.md.
You are absolutely right Michael. I misread the comment and thought that, in absence of paramenters, the expected behavior was to display the file content. My apologies for the mistake Jonathan.
Nice idea! Something a bit more elaborate (just for fun):
With this function we can use the heredoc syntax to write multi-line notes:
You also don't need to quote your notes anymore:
You mean stdin here, right?
Yea, sorry I guess I was thinking from a different perspective.
Hi Jonathan, I just tried your code and I was suprised to find that when I call the
notes
command without parameters, it doesn't show the content of thenotes.md
file. Instead it expects me to introduce the note content itself, and it doesn't write it to file till I do Ctrl + C. Hmm... I'll find out how to fix this.That looks like it's the intended behaviour to make it easy to write multi-line notes. If you'd rather have it just show the notes, then change the second branch of the
if
statement to justcat "$HOME/notes.md
.You are absolutely right Michael. I misread the comment and thought that, in absence of paramenters, the expected behavior was to display the file content. My apologies for the mistake Jonathan.
Good call.
Excellent Jonathan! Really nice addition.