Last active
July 10, 2024 04:04
-
-
Save mlongval/c5bba043980b377f2dfcaf6e4958633d to your computer and use it in GitHub Desktop.
Make Zsh never go below the last 3 lines on screen. Useful if KDE Panel covers bottom of terminal when working.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Little function to prevent Zsh from going below the bottom 3rd line of your terminal. | |
# Michael Longval | |
# mlongval <at> gmail.com | |
# Tags: KDE Konsole Zsh z-shell | |
# I was having trouble with KDE Panels covering my Konsole sometimes | |
# (would have to stop typing and click the panel to make it automatically disappear.) | |
# It works by printing 2 new-line characters and then going 2 lines back up | |
# to the original place, thus keeping your prompt always on the 3rd line from the bottom. | |
# Add this to your .zshrc | |
# Function to add newlines and move the cursor up | |
function add_padding() { | |
# Add newlines | |
print -n "\n\n" | |
# Move cursor up 2 lines | |
print -n "\e[2A" | |
} | |
# Store the existing prompt | |
ORIGINAL_PROMPT=$PROMPT | |
# Define a new prompt that includes padding and the original prompt | |
function prompt_with_padding() { | |
add_padding | |
print -n "${ORIGINAL_PROMPT}" | |
} | |
# Set the custom prompt function | |
PROMPT='$(prompt_with_padding)' | |
# Ensure the prompt is set correctly when precmd is called | |
precmd() { add_padding } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment