Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Would like an alias to read the part of the current command line that precedes the alias



On Oct 12, 11:15pm, Aaron Davies wrote:
}
} First, and I think this is general, it triggers again off of a blank
} command line (i.e. pressing return a second time) after the specified
} time has elapsed.

You can fix this by keeping track of $HISTCMD and skipping the alert
if it hasn't incremented.

} Second, and this is probably due to my setup, I can't get the failure
} detection working. The third growlnotify call below should have a -a
} argument of "Problem Reporter".
}
} Any idea what I'm doing wrong?

My example was incomplete.  I tested without the (( SECONDS > N )) and
that resets $? before the part after the && happens.

    typeset -g _LASTALERT=$HISTCMD
    preexec() {
      SECONDS=0
    }
    precmd() {
      local alert="${${?/0/Terminal}//<->*/Problem Reporter}"
      (( _LASTALERT < HISTCMD && SECONDS > 1 )) &&
        growlnotify -p "Very Low" -a "$alert" -m "$history[$_LASTALERT]"
      _LASTALERT=$HISTCMD
    }

Note that this is also going to put up a dialog if you interrupt a
command with ctrl-c.  Fixing that would involve saving $? and checking
for what signal it indicates was received, i.e. ^C is 130.



Messages sorted by: Reverse Date, Date, Thread, Author