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.
# 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