Zsh on RHEL 7 behaves the same a way, i.e. during ssh logout the terminal is cleared.
(Depending on the terminal the last terminal output is lost, or it is just scrolled out of view.)
This is because of /etc/zlogout
- which is part of the zsh package - is containing:
clear
(it does not contain other commands)
You can override this clearing in your own .zlogout
file via completely disabling the reading of /etc/zlogout
during logout:
$ cat ~/.zlogout
setopt norcs
Disabling the rcs option disables the sourcing of certain run control files - probably hence the name: no Run Control Sourcing
Well, according to some of your edits you've got CTRL+J
bound to a bindkey
macro command. That explains your bash
issue considering readline
's default behavior.
Generally readline
reads input in something very like stty raw
mode. Input chars are read in as soon as they are typed and the shell's line-editor handles its own buffering. readline
sets the terminal to raw when it takes the foreground, and it restores it to whatever its state was beforehand when calling up another foreground process group.
CTRL+J
is an ASCII newline. ABCDEFGHIJ
is 10 bytes from NUL. Because you have configured readline
to eat this character and subsequently to expand away what remains of any command-line on which it does with menu-completion, type-ahead won't work. The terminal is in a different state when the type-ahead is buffered by the kernel's line-discipline than it is when readline
is in the foreground.
When readline
is in the foreground it does its own translation for input carriage returns -> newlines and the terminal driver doesn't convert it at all. When you enter your type-ahead input, though, the terminal driver will typically translate returns to newlines as can be configured with stty [-]icrnl
. And so your return key is sufficient for commands entered live, but the newlines sent by the terminal's line-discipline are being interpreted as menu-complete commands.
You might tell the terminal driver to stop this translation with stty -icrnl
. This is likely to take at least a little bit of getting used to. Other commands that accept terminal input will usually expect newlines rather than returns, and so you'll either have to explicitly use CTRL+J
when they control the foreground, or else teach them to handle the returns as bash
does.
You've already mentioned that read
doesn't work as expected when reading form the terminal. Again, it likely would if you explicitly used CTRL+J
to end an input line. Or... you can teach it:
read()
if [ -t 0 ]
then command read -d $'\r' "$@"
else command read "$@"
fi
It will probably be a lot less hassle in the long-run if you found a different key for menu-complete, though. Newlines are kind of a big deal for most terminal applications.
Best Answer
You virtually answered your own question. Just run:
See:
for details on how to invoke
zsh
.