Skip to content

Commit

Permalink
Merge pull request #14 from devilbox/release-1.0.5
Browse files Browse the repository at this point in the history
Streamline log output
  • Loading branch information
cytopia authored Dec 17, 2022
2 parents a49f5f2 + f1964cf commit d64670a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 4 additions & 4 deletions test/01.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ touch "${DIR_PATH}/file 2"
### 02. Setup expected
###
{
echo "[OK] ADD: succeeded: ./dir 1"
echo "[OK] ADD: succeeded: ./dir 2"
echo "[OK] ADD: succeeded: ./dir 3"
echo "[OK] ADD: succeeded: ./dir 4"
echo "[OK] ADD succeeded: ./dir 1"
echo "[OK] ADD succeeded: ./dir 2"
echo "[OK] ADD succeeded: ./dir 3"
echo "[OK] ADD succeeded: ./dir 4"
} > "${SCRIPT_PATH}/01.expected"


Expand Down
16 changes: 8 additions & 8 deletions watcherd
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ MY_DATE="2022-12-17"
MY_URL="https://github.com/devilbox/watcherd"
MY_AUTHOR="cytopia <[email protected]>"
MY_GPGKEY="0xA02C56F0"
MY_VERSION="1.0.4"
MY_VERSION="1.0.5"
MY_LICENSE="MIT"

# Default settings
Expand Down Expand Up @@ -152,11 +152,11 @@ function trigger() {
if [ "${changes}" -eq "1" ]; then
if eval "${action}"; then
if [ "${verbose}" -gt "0" ]; then
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}"
printf "%s: [%s] [OK] %s succeeded: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRG" "${action}"
fi
return 0
else
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRIGGER" "${action}" >&2
printf "%s: [%s] [ERR] %s failed: %s\\n" "${MY_NAME}" "$( date '+%Y-%m-%d %H:%M:%S' )" "TRG" "${action}" >&2
# Also return 0 here in order to not abort the loop
return 0
fi
Expand Down Expand Up @@ -283,7 +283,7 @@ fi
# Initial add
for d in ${ALL_DIRS}; do
# Only CHANGE if adding was successful
if action "${d}" "${CMD_ADD}" "ADD:" "${VERBOSE}"; then
if action "${d}" "${CMD_ADD}" "ADD" "${VERBOSE}"; then
CHANGES=1
fi
done
Expand Down Expand Up @@ -311,11 +311,11 @@ if [ "${WATCHER}" = "inotify" ]; then
"${WATCH_DIR}" | while read -r output; do
d="${output##*\\}"
if [[ "${output}" =~ ^(CREATE|MOVED_TO),ISDIR/\\ ]]; then
if action "${d}" "${CMD_ADD}" "ADD:" "${VERBOSE}"; then
if action "${d}" "${CMD_ADD}" "ADD" "${VERBOSE}"; then
trigger "${CMD_TRIGGER}" "1" "${VERBOSE}"
fi
elif [[ "${output}" =~ ^(DELETE|MOVED_FROM),ISDIR/\\ ]]; then
if action "${d}" "${CMD_DEL}" "DEL:" "${VERBOSE}"; then
if action "${d}" "${CMD_DEL}" "DEL" "${VERBOSE}"; then
trigger "${CMD_TRIGGER}" "1" "${VERBOSE}"
fi
fi
Expand All @@ -342,14 +342,14 @@ else

# Run ADD command
for d in $ADD_DIRS; do
if action "${d}" "${CMD_ADD}" "ADD:" "${VERBOSE}"; then
if action "${d}" "${CMD_ADD}" "ADD" "${VERBOSE}"; then
CHANGES=1
fi
done

# Run DEL command
for d in $DEL_DIRS; do
if action "${d}" "${CMD_DEL}" "DEL:" "${VERBOSE}"; then
if action "${d}" "${CMD_DEL}" "DEL" "${VERBOSE}"; then
CHANGES=1
fi
done
Expand Down

0 comments on commit d64670a

Please sign in to comment.