Created
April 6, 2018 19:56
-
-
Save pop/f07aa1d145c96b2604762531a116e79c to your computer and use it in GitHub Desktop.
A script for taking notes more easily.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Script: notes.sh | |
# Author: Elijah C. M. Voigt | |
# License: MIT | |
# | |
# Installation: | |
# Add this to your path, make it executable, and add this line to your ${SHELL}rc | |
# alias notes='. notes.sh' | |
# That will add the command `notes` to your shell. | |
# | |
# About: | |
# This will create a git repository at ~/Notes (configurable). | |
# Every day it will create a new entry at ~/Notes/YEAR/MONTH/DAY (configurable). | |
# The first time you run it in a day it will populate the file with a template (configurable). | |
# When `notes` is run after that throughout the day it will open that file with your cursor at the end (configurable). | |
# Every time you close the file it saves and commits the file with the commit message being the time you opened the file (configurable). | |
USAGE="notes: for note taking. | |
Usage: | |
notes [-h | --help] [quick note]"; | |
if [[ $1 == '-h' || $1 == '--help' ]]; then | |
echo "$USAGE"; | |
return 0 | |
fi | |
QUIET=1; | |
NOTES_DIR=$HOME/Notes; | |
TODAY_DIR=$NOTES_DIR/`date +%Y/%m`; | |
TODAY_FILE=$TODAY_DIR/`date +%d`; | |
COMMIT_MESSAGE=`date +%H:%M:%s`; | |
TEMPLATE="# `date +%Y-%m-%d` | |
## TODO | |
## Worklog | |
"; | |
STDIN_NOTE=$@ | |
if [[ ! -f $TODAY_DIR ]]; then | |
mkdir -p $TODAY_DIR; | |
fi | |
if [[ ! -f $TODAY_FILE ]]; then | |
echo "$TEMPLATE" > $TODAY_FILE; | |
fi | |
pushd $NOTES_DIR &> /dev/null; | |
if [[ -z $STDIN_NOTE ]]; then | |
# $EDITOR $TODAY_FILE; | |
`which vim` '+normal Go' $TODAY_FILE; | |
else | |
echo $STDIN_NOTE >> $TODAY_FILE; | |
fi | |
if [[ $QUIET ]]; then | |
git add --all &> /dev/null; | |
git commit --message "$COMMIT_MESSAGE" &> /dev/null; | |
else | |
git add --all; | |
git commit --message "$COMMIT_MESSAGE"; | |
fi | |
popd &> /dev/null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment