Last active
October 6, 2020 20:21
-
-
Save revarcline/ead33b5e15b0341d1beabf6e1639832a to your computer and use it in GitHub Desktop.
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/bash | |
# diary.sh - simple diary organization script | |
# creates new or edits existing diary entry using $EDITOR. | |
# will create month and year directories as needed. | |
# files will be in markdown (.md) format. | |
# files are sorted as follows: | |
# yyyy/ | |
# | | |
# -mm/ | |
# | | |
# -yy.mm.dd.md | |
# | |
# keep this script in root dir of diary, alias locally in shell rc for use. | |
# eg: alias diary='~/diary/diary.sh' | |
# | |
# usage: diary -o yy mm dd to open a diary entry in $EDITOR | |
# diary -g 'commit message' to push to github | |
DIARYDIR=$(cd `dirname $0` && pwd) | |
if [[ $1 == '-o' ]] && [[ "$2$3$4" =~ [0-9]{2}[0-1][0-9][0-3][0-9] ]]; then | |
if [ ! -d "$DIARYDIR/20$2/$3" ]; then | |
mkdir $DIARYDIR/20$2/$3 | |
fi | |
NEWENTRY=$DIARYDIR/20$2/$3/20$2-$3-$4.md | |
$EDITOR $NEWENTRY | |
elif [[ $1 == '-g' ]] && [[ -n "$2" ]]; then | |
cd $DIARYDIR | |
git add -A | |
git commit -m "$2" | |
git push -u origin master | |
cd $OLDPWD | |
else | |
>&2 echo "Invalid arguments: | |
'$1 $2 $3 $4' | |
------------------ | |
to open entry: diary -o yy mm dd | |
to push to git: diary -g 'commit message'" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment