Is there a way to prevent the cursor from reaching the bottom of the terminal?
You can change your terminal prompt so that it echos five carriage returns and then uses an ansi escape sequence to move back up five lines before it finishes the rest of the prompt. If this works for you, you can put it in your .bashrc to make it permanent. Copy and paste this into your terminal :
PS1='\n\n\n\n\n\[\033[5A\]\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'
The '\n\n\n\n\n' moves down five lines and '[\033[5A]' moves back up five lines. You can modify both of those if you want more space.
You could try using tput
to change your terminal's scroll region:
tput csr 1 $((LINES/2))
If the shell's checkwinsize
option is enabled, then $LINES
should get updated if the terminal is resized - however in order to re-run the tput csr
command when that happens, you will need to capture the SIGWINCH
signal. You could add such a trap to your interactive shell initialization file ~/.bashrc
as follows:
trap 'tput csr 1 $((LINES/2))' WINCH ; kill -s WINCH $$
The second part of the command kill -s WINCH $$
sends an initial SIGWINCH
so that the tput csr
command gets run when the shell is first invoked as well.
References:
tput: Portable Terminal Control
Work the Shell - Dealing with Signals
Why not just use the clear
command from time to time?