Skip to content

Instantly share code, notes, and snippets.

@Adzz
Created August 1, 2017 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Adzz/b543c33b438727dbd82f3fcf53a1d953 to your computer and use it in GitHub Desktop.
Save Adzz/b543c33b438727dbd82f3fcf53a1d953 to your computer and use it in GitHub Desktop.
Trying to find a way to keep the prompt in the middle of the terminal
# see here: https://superuser.com/questions/1106674/how-to-add-blank-lines-above-the-bottom-in-terminal#_=_
# the n flag on echo eliminates new line, e flag interprets the exit codes
# echo -ne "\eD" moves down and scrolls the viewport
# echo -ne "\eM" moves up and scrolls the viewport if necessary
# "\e[B" and "\e[A" move up and down respectively constraining within the viewport
# for those two there are multipliers: "\e[3A" will repeat "\e[A" 3 times
# tput lines returns us the current number of rows in the viewport - i.e. how tall it is.
# this just doesnt seem to work
limit=$(($(tput lines) / 2))
echo -ne "\e[$limitA"
# only works the way we intend if we are at the bottom
# because we cant read current cursor position
echo -ne "$(printf '\eD%.0s' $(seq 1 $limit))\e[$(($(tput lines) / 2))A"
# destructive - loses most recent history for the number of lines we move back
# still best so far
# aliased to middle in ~/zshrc
tput cup $(($(tput lines) / 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment