Can I have the terminal prompt at the vertical middle of a window?
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)
terminal zsh iterm2 iterm
add a comment |
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)
terminal zsh iterm2 iterm
add a comment |
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)
terminal zsh iterm2 iterm
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)
terminal zsh iterm2 iterm
terminal zsh iterm2 iterm
asked Jan 2 at 16:07
edmzedmz
11815
11815
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The following code (uses zsh features, but the priciple can be used with other shells, too) defines two shell functions, prompt_middle
and prompt_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.
# load terminfo modules to make the associative array $terminfo available
zmodload zsh/terminfo
# save current prompt to parameter PS1o
PS1o="$PS1"
# calculate how many lines one half of the terminal's height has
halfpage=$((LINES/2))
# construct parameter to go down/up $halfpage lines via termcap
halfpage_down=""
for i in {1..$halfpage}; do
halfpage_down="$halfpage_down$terminfo[cud1]"
done
halfpage_up=""
for i in {1..$halfpage}; do
halfpage_up="$halfpage_up$terminfo[cuu1]"
done
# define functions
function prompt_middle() {
# print $halfpage_down
PS1="%{${halfpage_down}${halfpage_up}%}$PS1o"
}
function prompt_restore() {
PS1="$PS1o"
}
Personally instead of toggling between two modes I would use a much simpler approach (you need the definitions of $halfpage_up/down
from above):
magic-enter () {
if [[ -z $BUFFER ]]
then
print ${halfpage_down}${halfpage_up}$terminfo[cuu1]
zle reset-prompt
else
zle accept-line
fi
}
zle -N magic-enter
bindkey "^M" magic-enter
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).
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1389834%2fcan-i-have-the-terminal-prompt-at-the-vertical-middle-of-a-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The following code (uses zsh features, but the priciple can be used with other shells, too) defines two shell functions, prompt_middle
and prompt_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.
# load terminfo modules to make the associative array $terminfo available
zmodload zsh/terminfo
# save current prompt to parameter PS1o
PS1o="$PS1"
# calculate how many lines one half of the terminal's height has
halfpage=$((LINES/2))
# construct parameter to go down/up $halfpage lines via termcap
halfpage_down=""
for i in {1..$halfpage}; do
halfpage_down="$halfpage_down$terminfo[cud1]"
done
halfpage_up=""
for i in {1..$halfpage}; do
halfpage_up="$halfpage_up$terminfo[cuu1]"
done
# define functions
function prompt_middle() {
# print $halfpage_down
PS1="%{${halfpage_down}${halfpage_up}%}$PS1o"
}
function prompt_restore() {
PS1="$PS1o"
}
Personally instead of toggling between two modes I would use a much simpler approach (you need the definitions of $halfpage_up/down
from above):
magic-enter () {
if [[ -z $BUFFER ]]
then
print ${halfpage_down}${halfpage_up}$terminfo[cuu1]
zle reset-prompt
else
zle accept-line
fi
}
zle -N magic-enter
bindkey "^M" magic-enter
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).
add a comment |
The following code (uses zsh features, but the priciple can be used with other shells, too) defines two shell functions, prompt_middle
and prompt_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.
# load terminfo modules to make the associative array $terminfo available
zmodload zsh/terminfo
# save current prompt to parameter PS1o
PS1o="$PS1"
# calculate how many lines one half of the terminal's height has
halfpage=$((LINES/2))
# construct parameter to go down/up $halfpage lines via termcap
halfpage_down=""
for i in {1..$halfpage}; do
halfpage_down="$halfpage_down$terminfo[cud1]"
done
halfpage_up=""
for i in {1..$halfpage}; do
halfpage_up="$halfpage_up$terminfo[cuu1]"
done
# define functions
function prompt_middle() {
# print $halfpage_down
PS1="%{${halfpage_down}${halfpage_up}%}$PS1o"
}
function prompt_restore() {
PS1="$PS1o"
}
Personally instead of toggling between two modes I would use a much simpler approach (you need the definitions of $halfpage_up/down
from above):
magic-enter () {
if [[ -z $BUFFER ]]
then
print ${halfpage_down}${halfpage_up}$terminfo[cuu1]
zle reset-prompt
else
zle accept-line
fi
}
zle -N magic-enter
bindkey "^M" magic-enter
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).
add a comment |
The following code (uses zsh features, but the priciple can be used with other shells, too) defines two shell functions, prompt_middle
and prompt_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.
# load terminfo modules to make the associative array $terminfo available
zmodload zsh/terminfo
# save current prompt to parameter PS1o
PS1o="$PS1"
# calculate how many lines one half of the terminal's height has
halfpage=$((LINES/2))
# construct parameter to go down/up $halfpage lines via termcap
halfpage_down=""
for i in {1..$halfpage}; do
halfpage_down="$halfpage_down$terminfo[cud1]"
done
halfpage_up=""
for i in {1..$halfpage}; do
halfpage_up="$halfpage_up$terminfo[cuu1]"
done
# define functions
function prompt_middle() {
# print $halfpage_down
PS1="%{${halfpage_down}${halfpage_up}%}$PS1o"
}
function prompt_restore() {
PS1="$PS1o"
}
Personally instead of toggling between two modes I would use a much simpler approach (you need the definitions of $halfpage_up/down
from above):
magic-enter () {
if [[ -z $BUFFER ]]
then
print ${halfpage_down}${halfpage_up}$terminfo[cuu1]
zle reset-prompt
else
zle accept-line
fi
}
zle -N magic-enter
bindkey "^M" magic-enter
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).
The following code (uses zsh features, but the priciple can be used with other shells, too) defines two shell functions, prompt_middle
and prompt_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.
# load terminfo modules to make the associative array $terminfo available
zmodload zsh/terminfo
# save current prompt to parameter PS1o
PS1o="$PS1"
# calculate how many lines one half of the terminal's height has
halfpage=$((LINES/2))
# construct parameter to go down/up $halfpage lines via termcap
halfpage_down=""
for i in {1..$halfpage}; do
halfpage_down="$halfpage_down$terminfo[cud1]"
done
halfpage_up=""
for i in {1..$halfpage}; do
halfpage_up="$halfpage_up$terminfo[cuu1]"
done
# define functions
function prompt_middle() {
# print $halfpage_down
PS1="%{${halfpage_down}${halfpage_up}%}$PS1o"
}
function prompt_restore() {
PS1="$PS1o"
}
Personally instead of toggling between two modes I would use a much simpler approach (you need the definitions of $halfpage_up/down
from above):
magic-enter () {
if [[ -z $BUFFER ]]
then
print ${halfpage_down}${halfpage_up}$terminfo[cuu1]
zle reset-prompt
else
zle accept-line
fi
}
zle -N magic-enter
bindkey "^M" magic-enter
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).
edited Jan 2 at 20:30
answered Jan 2 at 20:25
mpympy
18.2k45472
18.2k45472
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1389834%2fcan-i-have-the-terminal-prompt-at-the-vertical-middle-of-a-window%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown