zsh shell integration fixes

Issue escapes in right order to make shell integration (last cmd output and cmd returnvalue) work, assuming a single-line prompt.

Refactored to make things a bit more zsh-idiomatic, like using hooks rather than overwriting preexec/cmd so it plays well with other plugins.