I just realized that I hunch over a lot when using the terminal since the prompt is always at the bottom of the terminal window, which is vertically maximized.
I would like the prompt to be at the vertical middle of the window (or in a point near where my eyes are pointed to).
You could argue that I can resize the window and achieve that, but sometimes I like the vertical space (eg. when running ls -la
). So, ideally, I could toggle the position of the prompt between some point and the bottom of the window.
(I'm using iTerm under MacOS with zsh, but I'm interested in an agnostic/generic way of doing this)
Best Answer
The following code (uses zsh features, but the priciple can be used with other shells, too) defines two shell functions,
prompt_middle
andprompt_restore
.The first function keeps the prompt always above the middle of the terminal by forcing an appropriate number of empty lines below the prompt. The latter funtion restores the normal behavior.
You can assign these functions to some shortcuts or use some logic to toggle between these two modes.
Personally instead of toggling between two modes I would use a much simpler approach (you need the definitions of
$halfpage_up/down
from above):This checks if the current command line is empty (see my other answer) and if so move the prompt up to the middle of the terminal. Now you can fast-forward your prompt with an additional press of the
ENTER
key (or maybe you want to call it double-press similar to a double-click).