Skip to content

Instantly share code, notes, and snippets.

@YajJackson
Created August 30, 2019 12:54
Show Gist options
  • Save YajJackson/e641b9fef468d1f60b7932bcd373eddf to your computer and use it in GitHub Desktop.
Save YajJackson/e641b9fef468d1f60b7932bcd373eddf to your computer and use it in GitHub Desktop.
#!/bin/sh
# Note file
note_file=~/_notes.md
# Create Note file if it does not exist
if [ ! -f "$note_file" ]; then
touch $note_file
fi
# Get Date
date=`date '+%Y-%m-%d'`
# Get line number in notes for today (2019-09-23)
date_line=`grep -n $date $note_file | sed -nE 's/([0-9]):.*/\1/p'`
# If the line does not exist
# append today's (YYYY-MM-DD) to the end of the file, and open at the end of the file
if [ -z "$date_line" ]; then
echo "## $date\n" >> $note_file
line_number=$(($((`grep -n $date $note_file | sed -nE 's/([0-9]):.*/\1/p'`))+1))
vim $note_file +$line_number
exit
fi
# Otherwise, open the file with vim at date_line + 1
vim $note_file +$(($date_line+1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment