diff --git a/mlog b/mlog new file mode 100755 index 0000000..0fe79c9 --- /dev/null +++ b/mlog @@ -0,0 +1,39 @@ +#!/bin/bash +# Monthly logging script +# Call mlog and it will update a log file + +# Set the default mlog folder +[[ -z $MLOG_FOLDER ]] && MLOG_FOLDER="$HOME/mlog" + +# Make sure that the folder exists +[[ ! -d $MLOG_FOLDER ]] && mkdir -pv $MLOG_FOLDER + +# Make sure that we have a valid TMPDIR +[[ -z $TMPDIR ]] && TMPDIR='/tmp' + +# Make sure that we have a valid EDITOR +[[ -z $EDITOR ]] && EDITOR=vim + +MLOG_HDR='' + +if [[ -x $HOME/bin/stardate ]] +then + [[ -z $MLOG_RANK ]] && MLOG_RANK='Chief Engineer' + + MLOG_HDR="$MLOG_RANK's log, Stardate $($HOME/bin/stardate)\n" +fi + +MLOG_HDR="$MLOG_HDR[$(date)]" + +MLOG_FILE="$TMPDIR/mlog-tmp-$$" + +$EDITOR $MLOG_FILE + +[[ ! -s $MLOG_FILE ]] && exit 0 + +MLOG_LOG="$MLOG_FOLDER/$(date +%Y-%m)" + +echo -e "$MLOG_HDR\n" >> $MLOG_LOG +cat $MLOG_FILE >> $MLOG_LOG +echo -e "\n----------------------------------------\n" >> $MLOG_LOG +