Move editor check to a separate function

This commit is contained in:
Ivan R. 2023-03-13 00:20:41 +05:00
parent ce4bee4a82
commit ad76ee9733
No known key found for this signature in database
GPG key ID: 56C7BAAE859B302C

View file

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