# Command logging. You can put this file in /etc/profile.d (Ubuntu) or call it from /etc/profile.
# By default on normal Unix systems the logs will go to a catch-all log destination, eg on Linux
# usually /var/log/messages.
# See https://shearer.org/notes/cloba/

__LAST_COMMAND="$(history 1)"

declare -r BASH_COMMAND

declare -r __TRAP='
__THIS_COMMAND="$(history 1)"
if [ "$__LAST_COMMAND" != "$__THIS_COMMAND" ]
then
    __LAST_COMMAND="$__THIS_COMMAND"
    if [ "$PROMPT_COMMAND" != "$BASH_COMMAND" ]
    then
	'"$(which logger)"' -p local3.notice -- "-- CMD -- '"$(pwd)"' $LOGNAME@$HOSTNAME[$$]: $__LAST_COMMAND"
    fi
fi'

# This is the actual invocation - the DEBUG trap fires before any line is executed
# by bash, and this trap is re-instated before every command prompt is displayed.
# but this avoids other problems.)
declare -r PROMPT_COMMAND='trap "$__TRAP" DEBUG'

# This ensures all duplicates will be logged.
declare -r HISTCONTROL=''
