Fix small issues reported by shellcheck
- Use subshells instead of "cd -". - Use quotes around variables. - Add "set -eo pipefail" to catch errors.
This commit is contained in:
parent
f77bc126ac
commit
98eb53a718
1 changed files with 13 additions and 9 deletions
22
histd.sh
22
histd.sh
|
@ -3,6 +3,8 @@
|
|||
# Histd: how I spent this day.
|
||||
# A simple but useful personal diary CLI utility.
|
||||
|
||||
set -eo pipefail
|
||||
|
||||
# Check if a text editor is specified
|
||||
function _check_editor {
|
||||
if [[ $EDITOR == "" ]]; then
|
||||
|
@ -16,26 +18,28 @@ function _check_editor {
|
|||
function edit_note {
|
||||
# Create dirs (base_dir/year/month)
|
||||
WORKDIR="$BASE_DIR/$(date +%Y)/$(date +%m)"
|
||||
mkdir -p $WORKDIR
|
||||
mkdir -p "$WORKDIR"
|
||||
|
||||
# Generate file name
|
||||
PATH_TO_FILE="$WORKDIR/$(date +%d).md"
|
||||
|
||||
# Open editor
|
||||
_check_editor
|
||||
cd $BASE_DIR
|
||||
$EDITOR $PATH_TO_FILE
|
||||
cd - > /dev/null
|
||||
(
|
||||
cd $BASE_DIR
|
||||
$EDITOR "$PATH_TO_FILE"
|
||||
)
|
||||
}
|
||||
|
||||
# Create an archive with all notes
|
||||
function backup {
|
||||
ARCHIVE_PATH=~/histd-$(date +%F).tar.xz
|
||||
cd $BASE_DIR
|
||||
tar cfJ $ARCHIVE_PATH ../histd
|
||||
cd - > /dev/null
|
||||
(
|
||||
cd $BASE_DIR
|
||||
tar cfJ "$ARCHIVE_PATH" ../histd
|
||||
)
|
||||
|
||||
echo Saved to $ARCHIVE_PATH
|
||||
echo "Saved to $ARCHIVE_PATH"
|
||||
}
|
||||
|
||||
# Concatenate all files and prefix each with the filename.
|
||||
|
@ -54,7 +58,7 @@ function last {
|
|||
_check_editor
|
||||
LAST_FILE=$(find $BASE_DIR -type f -name "*.md" | tail -1)
|
||||
cd $BASE_DIR
|
||||
$EDITOR $LAST_FILE
|
||||
$EDITOR "$LAST_FILE"
|
||||
cd - > /dev/null
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue