#!/bin/bash if [ "$1" == "-h" ] ; then echo " nj - new journal, create/open markdown text file for human writing - creates new or opens existing file in the user's preferred EDITOR (e.g. if defined in .bashrc) else nano is used as default. Usage: nj nj my-title ~/projects/foo ~/bin/nj-ucsc.tmpl The first example above would create new timestamped file in the default notes directory. The second example would create/open existing file called 'my-title.md' in a directory 'projects/foo' using a custom user template called 'nj-ucsc.tmpl' Setup .bashrc.local or other user specific config file for defining variables: 'export EDITOR=vim' or set temporarily for current session: 'export author='first last' " echo "$(tput setaf 6)$EDITOR $(tput setaf 7)is currently set as editor" exit 0 fi set -e defTitle=journal defDir=notes defApp=nano #nano,vim,nvim,gvim,emacs,atom,subl defTemplate=$HOME/bin/nj.tmpl title=$1 basedir=$2 mdtemplate=$3 app=$EDITOR if [[ $MY_NAME ]] & [[ -z $author ]]; then author=$MY_NAME fi if [[ -z $author ]]; then author=$USER fi if [[ -z $title ]]; then title=$defTitle fi if [[ -z $basedir ]]; then basedir=$HOME/$defDir fi if [[ -z $mdtemplate ]]; then mdtemplate=$defTemplate fi if [[ -z $app ]]; then app=$defApp fi fn=$basedir/$(date +"%Y-%m-%d")-$title.md if [[ -e $fn ]] then echo "opening $fn" $app $fn else echo "creating $fn" cat $mdtemplate | sed -E "s|(date: ).+|\1$(date --iso-8601='seconds') |" | sed -E "s|(author: ).+|\1$author |" | sed -E "s|(title: ).+|\1$title |" >> $fn $app $fn fi