/home/alex/dev/fa-debug.sh (1)

From RaySoft
#!/bin/bash -
# ------------------------------------------------------------------------------
# fa-debug.sh
# ===========
#
# Project   Folder Actions
# Scope     macOS
# Copyright (C) 2024 by RaySoft, Zurich, Switzerland
# License   GNU General Public License (GPL) 2.0
#           https://www.gnu.org/licenses/gpl2.txt
#
# ------------------------------------------------------------------------------

set -o 'noglob' -o 'nounset' -o 'pipefail' # -o 'errexit' -o 'xtrace'

# ------------------------------------------------------------------------------

FA_LOG_PATH="${HOME}/dev/folder_actions/logs"
FA_LOG_FILE="${FA_LOG_PATH}/folder_actions-debug.log"

# ------------------------------------------------------------------------------

DATE=('/usr/local/bin/gdate')
MKDIR=('/usr/local/bin/gmkdir' '--parents')
PRINTF=('/usr/local/bin/gprintf')

# ------------------------------------------------------------------------------

# Make the log directory if it doesn' exist
[[ -d "${FA_LOG_PATH}" ]] || "${MKDIR[@]}" "${FA_LOG_PATH}"

# Ridirect STDOUT and STDERR to the log file
exec >>"${FA_LOG_FILE}" 2>&1

# Print a title to the log file
"${DATE[@]}" '+%n----- %F %T -----'

# Save the first argument to the variable 'path' and remove it
path="${1%%/}" && shift

# Print the current Bash version
echo "Bash '${BASH_VERSION}'"

# Print the path
echo "Path '${path}'"

# Print all remaining arguments
"${PRINTF[@]}" "Item '%s'\n" "$@"

# ------------------------------------------------------------------------------

exit 0

Usage