colorize hostname in command line prompt [duplicate]
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
This question already has an answer here:
Terminal prompt not wrapping correctly
6 answers
I wish to set a custom color for the hostname portion of my command line prompt (in bash).
In my .bashrc
file, the default command line prompt is:
PS1='[u@h W]$ '
To colorize the hostname only, I came up with this prompt:
PS1='[u@e[40;36mhe[0m W]$ '
I used different colors for each host I work on. The colorizing part seems to be working as expected. However, with the prompt above, navigation on the command line becomes dysfunctional. For example, at times I cannot move the cursor to the beginning or end of the line. If I switch back to the default prompt, everything works correctly again.
What's wrong with my colorized prompt? How can I properly specify a color for the hostname only?
It should not matter for this question, but I'm running Arch Linux KDE and I work in Konsole.
bash colors prompt konsole
marked as duplicate by Mikel, Community⦠May 8 at 1:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
2
down vote
favorite
This question already has an answer here:
Terminal prompt not wrapping correctly
6 answers
I wish to set a custom color for the hostname portion of my command line prompt (in bash).
In my .bashrc
file, the default command line prompt is:
PS1='[u@h W]$ '
To colorize the hostname only, I came up with this prompt:
PS1='[u@e[40;36mhe[0m W]$ '
I used different colors for each host I work on. The colorizing part seems to be working as expected. However, with the prompt above, navigation on the command line becomes dysfunctional. For example, at times I cannot move the cursor to the beginning or end of the line. If I switch back to the default prompt, everything works correctly again.
What's wrong with my colorized prompt? How can I properly specify a color for the hostname only?
It should not matter for this question, but I'm running Arch Linux KDE and I work in Konsole.
bash colors prompt konsole
marked as duplicate by Mikel, Community⦠May 8 at 1:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
This question already has an answer here:
Terminal prompt not wrapping correctly
6 answers
I wish to set a custom color for the hostname portion of my command line prompt (in bash).
In my .bashrc
file, the default command line prompt is:
PS1='[u@h W]$ '
To colorize the hostname only, I came up with this prompt:
PS1='[u@e[40;36mhe[0m W]$ '
I used different colors for each host I work on. The colorizing part seems to be working as expected. However, with the prompt above, navigation on the command line becomes dysfunctional. For example, at times I cannot move the cursor to the beginning or end of the line. If I switch back to the default prompt, everything works correctly again.
What's wrong with my colorized prompt? How can I properly specify a color for the hostname only?
It should not matter for this question, but I'm running Arch Linux KDE and I work in Konsole.
bash colors prompt konsole
This question already has an answer here:
Terminal prompt not wrapping correctly
6 answers
I wish to set a custom color for the hostname portion of my command line prompt (in bash).
In my .bashrc
file, the default command line prompt is:
PS1='[u@h W]$ '
To colorize the hostname only, I came up with this prompt:
PS1='[u@e[40;36mhe[0m W]$ '
I used different colors for each host I work on. The colorizing part seems to be working as expected. However, with the prompt above, navigation on the command line becomes dysfunctional. For example, at times I cannot move the cursor to the beginning or end of the line. If I switch back to the default prompt, everything works correctly again.
What's wrong with my colorized prompt? How can I properly specify a color for the hostname only?
It should not matter for this question, but I'm running Arch Linux KDE and I work in Konsole.
This question already has an answer here:
Terminal prompt not wrapping correctly
6 answers
bash colors prompt konsole
edited May 8 at 3:42
asked May 8 at 0:28
MountainX
4,4092367115
4,4092367115
marked as duplicate by Mikel, Community⦠May 8 at 1:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Mikel, Community⦠May 8 at 1:38
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Background
After the expansion is done for special prompt sequences, every character remaining in the prompt is counted in order to calculate the length of the prompt.
Problem
Since you've added the color sequences, which in fact shouldn't be counted for the length of a prompt, bash
now actually thinks that your prompt is longer than it really is.
Because of that, bash
can't know where is the beginning or the end of the line and that creates mentioned dysfunctionalities.
Solution
From bash
manual:
[ Begin a sequence of non-printing characters, which could be used to
embed a terminal control sequence into the prompt
] End a sequence of non-printing characters
Just add these around your color escape sequences so that they aren't counted for the prompt length.
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Background
After the expansion is done for special prompt sequences, every character remaining in the prompt is counted in order to calculate the length of the prompt.
Problem
Since you've added the color sequences, which in fact shouldn't be counted for the length of a prompt, bash
now actually thinks that your prompt is longer than it really is.
Because of that, bash
can't know where is the beginning or the end of the line and that creates mentioned dysfunctionalities.
Solution
From bash
manual:
[ Begin a sequence of non-printing characters, which could be used to
embed a terminal control sequence into the prompt
] End a sequence of non-printing characters
Just add these around your color escape sequences so that they aren't counted for the prompt length.
add a comment |Â
up vote
2
down vote
accepted
Background
After the expansion is done for special prompt sequences, every character remaining in the prompt is counted in order to calculate the length of the prompt.
Problem
Since you've added the color sequences, which in fact shouldn't be counted for the length of a prompt, bash
now actually thinks that your prompt is longer than it really is.
Because of that, bash
can't know where is the beginning or the end of the line and that creates mentioned dysfunctionalities.
Solution
From bash
manual:
[ Begin a sequence of non-printing characters, which could be used to
embed a terminal control sequence into the prompt
] End a sequence of non-printing characters
Just add these around your color escape sequences so that they aren't counted for the prompt length.
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Background
After the expansion is done for special prompt sequences, every character remaining in the prompt is counted in order to calculate the length of the prompt.
Problem
Since you've added the color sequences, which in fact shouldn't be counted for the length of a prompt, bash
now actually thinks that your prompt is longer than it really is.
Because of that, bash
can't know where is the beginning or the end of the line and that creates mentioned dysfunctionalities.
Solution
From bash
manual:
[ Begin a sequence of non-printing characters, which could be used to
embed a terminal control sequence into the prompt
] End a sequence of non-printing characters
Just add these around your color escape sequences so that they aren't counted for the prompt length.
Background
After the expansion is done for special prompt sequences, every character remaining in the prompt is counted in order to calculate the length of the prompt.
Problem
Since you've added the color sequences, which in fact shouldn't be counted for the length of a prompt, bash
now actually thinks that your prompt is longer than it really is.
Because of that, bash
can't know where is the beginning or the end of the line and that creates mentioned dysfunctionalities.
Solution
From bash
manual:
[ Begin a sequence of non-printing characters, which could be used to
embed a terminal control sequence into the prompt
] End a sequence of non-printing characters
Just add these around your color escape sequences so that they aren't counted for the prompt length.
edited May 8 at 1:31
answered May 8 at 0:55
Iskustvo
667118
667118
add a comment |Â
add a comment |Â