I'm currently customizing my terminal/bash command prompt for my mac. I was wondering if there was a way to keep the actually prompt in the middle/top top of page after running each command. I hate when it gets to the bottom of the screen then I have to clear it to get back to the top.
Asked
Active
Viewed 1,991 times
3 Answers
2
You can use an ANSI escape character to reposition the cursor prior displaying the prompt, but I don't think you're going to like the result; it's going to put the prompt above or on top of the output from the previous command.
PS1='\[\e[1;1H\]> '
"1;1" here represents the upper left-hand corner; you can vary the numbers to choose a different row/column if desired.

chepner
- 497,756
- 71
- 530
- 681
1
This answer seems to nearly work for me with some amendment but it still displays some odd behaviour:
PS1=$'\n\n\n\n\n\n\n\n\e[8A'"$PS1"

Mike
- 91
- 6
-
As itβs currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). β Community Jun 17 '22 at 10:07
-
1This worked for me! Thanks. Having the prompt at the bottom hurts my neck. β A. K. Aug 15 '22 at 05:00
0
Personally, I prefer the prompt at the bottom of the terminal, so I have this in my ~/.bashrc
:
__prompt_to_bottom_line() {
tput cup $LINES
}
alias clear='clear && __prompt_to_bottom_line'
__prompt_to_bottom_line
You can easily adapt it, e.g. by changing $LINES
to $(( LINES / 2 ))
you want it at the center of the screen.

Enlico
- 23,259
- 6
- 48
- 102