This code was at the end of my .zlogin on my mac and was causing .zlogin:152: parse error near `\n'
. The problem is rather bone-headed, but I went through trying to :set ff=unix
, :set ff=mac
in vim to try and remedy bad line endings.
function notify_preexec() {
# Note the date when the command started, in unix time.
CMD_START_DATE=$(date +%s)
# Store the command that we're running.
CMD_NAME="$1"
}
function notify_precmd() {
# Proceed only if we've run a command in the current shell.
# Proceed only if we've run a command in the current shell.
function notify_precmd() {
# Proceed only if we've run a command in the current shell.
if ! [[ -z $CMD_START_DATE ]]; then
# Note current date in unix time
CMD_END_DATE=$(date +%s)
# Store the difference between the last command start date vs. current date.
CMD_ELAPSED_TIME=$(($CMD_END_DATE - $CMD_START_DATE))
# Store an arbitrary threshold, in seconds.
CMD_NOTIFY_THRESHOLD=240
if [[ $CMD_ELAPSED_TIME -gt $CMD_NOTIFY_THRESHOLD ]]; then
# Beep or visual bell if the elapsed time (in seconds) is greater than threshold
# Send a notification
if [[ "$CMD_NAME" =~ 'rake' ]]; then
say "$CMD_NAME FINISHED IN $CMD_ELAPSED_TIME SECONDS"
fi
unset CMD_NAME
unset CMD_START_DATE
fi
fi
}
See it yet?
function notify_precmd() {
# Proceed only if we've run a command in the current shell.
# Proceed only if we've run a command in the current shell.
function notify_precmd() {
I somehow opened up the notify_precmd()
function twice. I was mostly focusing on a missing fi
and mismatched parens/braces.