Move editor check to a separate function
This commit is contained in:
parent
ce4bee4a82
commit
ad76ee9733
1 changed files with 10 additions and 12 deletions
22
histd.sh
22
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
|
||||
|
|
Loading…
Reference in a new issue