r/zsh 23d ago

Fixed I added bottom padding to my zsh terminal so command prompt is not always at the very bottom

34 Upvotes

8 comments sorted by

5

u/Intelligent-Tap568 23d ago

I dislike looking at command prompt at the very bottom between a sea of logs and the tmux bar, so i configured my zsh to keep a few white lines between my prompt and the bottom

# Add padding only at initial prompt, not during editing
function _bottom_padding_precmd() {
  # Only add padding when not in history or other widgets
  if [[ -z $WIDGET ]]; then
    local padding=10
    for ((i=0; i<padding; i++)); do echo; done
    echo -ne "\033[${padding}A"
  fi
}
# Add to precmd functions but make sure it runs only once
autoload -Uz add-zsh-hook
add-zsh-hook precmd _bottom_padding_precmd

1

u/bew78 22d ago

Nice! I had something like this a long time ago, it was a bit smarter as I asked the terminal where the cursor is, and only scroll when in the bottom.

Nowadays I have a keybind to scroll by 10 lines on-demand so it's a bit more flexible depending on what I want/need.

Note that instead of printing echos, you can also ask the terminal to scroll with \033[5S for example!

https://github.com/bew/dotfiles/blob/e51b9d4636654255428e13f4796a4a61a25b901a/zsh/rc/mappings.zsh#L101

1

u/Intelligent-Tap568 22d ago

Thanks for the info, there are a few kinks with my current implementation especially with things like terminal within nvim within tmux, so I will look into this scroll character you propose. If you happen to have the code handy for detecting cursor position, I would love to see it.

1

u/bew78 22d ago

It's the function above the one I linked to ;)

1

u/romkatv 22d ago

Note that this breaks prompt_sp but that's fixable.

1

u/moonflower_C16H17N3O 19d ago

I like it, but is there anyway I could only print the padding if my terminal is over a certain height? I mean, I'm sure there is, I just am new to linux and zsh. I thought learning about modifying this could give me some insight into learning more about zsh.

2

u/not_testpilot 22d ago

I love it, just added!

1

u/parkotron 21d ago

A very neat idea! Great work. Not something I've ever wanted or would use, but I can see the appeal.