128
votes
Accepted
Why ZSH ends a line with a highlighted percent symbol?
Yes, this happens because it is a "partial line". And by default zsh goes to the next line to avoid covering it with the prompt.
When a partial line is preserved, by default you will see an
...
101
votes
Terminal prompt not wrapping correctly
It is mostly to do with the size of the window assumed by the terminal is not the same as your actual window size. If you are using bash, you can try this.
$ shopt checkwinsize
If you don't get
...
62
votes
Accepted
In which situations are PS2, PS3, PS4 used as the prompt?
Here is what the bash documentation says:
PS1 The value of this parameter is expanded (see PROMPTING below)
and used as the primary prompt string. The default value is
``\s-\...
49
votes
tmux not colorizing PS1 prompt
On my machine the solution is to add
set -g default-terminal "xterm-256color"
to ~/.tmux.conf.
43
votes
Accepted
Why do I sometimes get repeatedly prompted with ">" in the terminal?
> is the default continuation prompt.That is what you will see if what you entered before had unbalanced quote marks.
As an example, type a single quote on the command line followed by a few ...
43
votes
Why ZSH ends a line with a highlighted percent symbol?
That's a specific feature of zsh (and now fish as well) to let you clearly see unterminated lines in a command's output.
In traditional shells, if a command outputs some data after the last newline ...
42
votes
What color codes can I use in my Bash PS1 prompt?
I wrote a bash function that can show you all the colors, if this helps.
function colorgrid( )
{
iter=16
while [ $iter -lt 52 ]
do
second=$[$iter+36]
third=$[$second+36]
...
41
votes
Accepted
Shorten path in zsh prompt
To get a similar effect like in bash, that is including the ..., try:
%(4~|.../%3~|%~)
This checks, if the path is at least 4 elements long (%(4~|true|false)) and, if true, prints some dots with the ...
38
votes
Accepted
How do I ask password by GUI prompt while using sudo in script?
You can ask password by means of GUI prompt with the help of -A, --askpass options for sudo.
From the sudo manpage:
-A, --askpass
Normally, if sudo requires a password, it will read ...
35
votes
Accepted
What is percent sign prompt in a shell?
That's the shell prompt, or more precisely, it's the shell's primary prompt (there are several). It's the shell's way of saying, "go ahead, I'm ready for input now".
The % prompt is common ...
33
votes
Accepted
Show only current and parent directory in bash prompt
Bash's prompt control features are rather static. If you want more control, you can include variables in your prompt; make sure you haven't turned off the promptvars option.
PS1='${PWD#"${PWD%/*/*}/"}...
31
votes
PS1='$(pwd)' why this works and why is this different from PS1=$(pwd)
When you simply assign a value to a variable, the $(...) expression is evaluated unless it is enclosed in single quotes (or backslash-escaped). To understand, try and compare these two:
A=$(pwd)
echo ...
26
votes
Terminal prompt not wrapping correctly
I once read somewhere (don't know where anymore) that using \001 and \002 instead of \[ and \] can solve this issue. It did for me.
By the way, defining PS1 does not have to look ugly.
green="\...
24
votes
How to make bash put prompt on a new line after cat command?
I prefer the following method...
cat example.txt ; echo
This doesn't doesn't evaluate the contents of example.txt or occasionally add a newline. It just echos a newline once the cat is done, is ...
23
votes
How to show the host name in Linux commandline prompt
Look into your ~/.bashrc or ~/.profile, there may be a commented prompt setup that should do what you want, like this one on our infra:
export PS1='\h:\w\$ '
Which looks like:
coolservername:~#
...
23
votes
tmux not colorizing PS1 prompt
My solution to this problem was setting
force_color_prompt=yes
in my .bashrc. Now my tmux prompt has color.
21
votes
Accepted
oh-my-zsh's prompt is slow: how to fix this
I don't know what oh-my-zsh puts in the prompt by default. Maybe it tries to identify the version control status, that's a very popular prompt component which might be time-consuming.
To see what's ...
20
votes
Accepted
Using variables to store terminal color codes for PS1?
The solution is to get the shell to substitute the color variables when defining the prompt, but not the functions. To do this, use the double quotes as you had originally tried, but escape the ...
20
votes
Accepted
Why is $ the default symbol for a user shell and # the default symbol for a root shell?
Historically the original /bin/sh Bourne shell would use $ as the normal prompt and # for the root user prompt (and csh would use %). This made it pretty easy to tell if you were running as superuser ...
18
votes
Accepted
Compact bash prompt when using a directory tree / filename
First of all, you might simply want to change the \w with \W. That way, only the name of the current directory is printed and not its entire path:
terdon@oregano:/home/mydirectory1/...
17
votes
Colorizing your terminal and shell environment?
I've honed my .bashrc over the years to work on both OSX and Ubuntu.
I've also reduced it in size to 28 lines with compact condition statements.
With it, my PS1 prompt looks like:
with time in red, ...
17
votes
Accepted
How can I make commands appear bold in zsh?
The old-fashioned way was to use POSTEDIT
POSTEDIT=$'\e[0m'
(and by the way this isn't bash, don't use a DEBUG trap to simulate preexec: zsh is where it's from) but since zsh 4.3.11 you can use the ...
17
votes
Accepted
Meaning of \[\e]0; in PS1 in .bashrc
The \e]0; is an escape sequence; \e is replaced with ASCII 27 (ESC), so the terminal receives the 4 characters ESC ] 0 ; tells xterm to set icon and title bar, that ends in BEL (\a).
So the sequence ...
16
votes
Why do I sometimes get repeatedly prompted with ">" in the terminal?
That will happen if you have an unclosed quote in your command. That's something like:
$ echo "test here
>
>
...
You can exit that mode by closing the quote (write a " or ', or whatever your ...
16
votes
Save cursor position and restore it in terminal
Most of the terminals you are likely to use implement escape sequences for saving and restoring the cursor position. Those are the sc (save cursor) and rc (restore cursor) capabilities in the ...
15
votes
Accepted
How to show the host name in Linux commandline prompt
Just change the value of the $PS1 environment variable:
PS1="\h$ "
where \h is replaced with the hostname. Add that to /etc/bash.bashrc to set it permanent.
15
votes
Bash prompt execute command every time a new prompt is displayed
Your problem is that $(git_prompt) is evaluated to some constant string before it is added to $PS1. You have to add the code instead:
PS1+='$(git_prompt)'
15
votes
Bash prompt execute command every time a new prompt is displayed
I fixed it now by using this as prompt
PS1="$green\u $r@ $red\h $r: $yellow\W \!$r \$(git_prompt) \n$yellow\$ $r"
before I concatenated multiple strings to one PS1 string, there seemed to be the ...
15
votes
Accepted
Why is something for $PS3 shown, even when $PS3 is empty?
Because the doc says so:
https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#Bash-Variables
PS3
The value of this variable is used as the prompt for the select command. If this ...
15
votes
Accepted
Terminal prompt overwrites current line
You've completely banjanxed the Bourne Again shell's idea of what's been printed and what it has to erase/rewrite as it displays command history and lets you edit the command line.
Breaking your ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
prompt × 623bash × 367
zsh × 110
shell × 86
terminal × 63
colors × 49
command-line × 47
linux × 31
shell-script × 26
tcsh × 21
ksh × 17
ssh × 14
escape-characters × 14
login × 13
command-history × 13
macos × 13
ubuntu × 12
git × 12
debian × 11
environment-variables × 11
gnome-terminal × 11
password × 10
hostname × 10
window-title × 10
sudo × 9