diff --git a/histd.sh b/histd.sh index ffe4164..7cb5d3a 100755 --- a/histd.sh +++ b/histd.sh @@ -3,6 +3,14 @@ # Histd: how I spent this day. # A simple but useful personal diary CLI utility. +# Check if a text editor is specified +function _check_editor { + if [[ $EDITOR == "" ]]; then + echo EDITOR is undefined + exit 1 + fi +} + function edit_note { # Creates the required directories and opens a text editor # so that the user can describe the day. @@ -14,13 +22,8 @@ function edit_note { # Generate file name PATH_TO_FILE="$WORKDIR/$(date +%d).md" - # Check editor - if [[ $EDITOR == "" ]]; then - echo EDITOR is undefined - return - fi - # Open editor + _check_editor cd $BASE_DIR $EDITOR $PATH_TO_FILE cd - > /dev/null @@ -47,12 +50,7 @@ function list { } function last { - # Check editor - if [[ $EDITOR == "" ]]; then - echo EDITOR is undefined - return - fi - + _check_editor LAST_FILE=$(ls -t $BASE_DIR/**/**/* | head -1) cd $BASE_DIR $EDITOR $LAST_FILE