From ad76ee9733f775b85c3ea92942b9de40807ae7b4 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Mon, 13 Mar 2023 00:20:41 +0500 Subject: [PATCH] Move editor check to a separate function --- histd.sh | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) 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