How can I get the bash to look colored like this?
-
daniel451 how come you have answered for your own question within the same timings.– kvaNov 16, 2017 at 14:20
-
6@kva Answering your own question at the same time as posting is encouraged across the Stack Exchange network.– CJ DennisJan 19, 2018 at 4:38
-
Related: askubuntu.com/questions/123268/…. It explains how individual parts of the prompt can be coloured differently.– FreezingFireDec 1, 2018 at 10:48
5 Answers
Open ~/.bashrc
in text editor and uncomment line:
#force_color_prompt=yes
to be:
force_color_prompt=yes
save then execute source ~/.bashrc
-
Doesn't exactly answer the question, but I like this result better (less distracting). Oct 1, 2016 at 18:27
-
-
Here is what mine looks like after your method: !2016-10-25 16:12:15.png Not exactly as in the question. Oct 25, 2016 at 20:19
-
1Is
force_color_prompt=yes
the intended way of enabling colors? To me forcing sounds like a workaround.– JaakkoJan 14, 2018 at 11:09 -
2I hope I didn't sound disrespectful with my comments, I'm just trying to understand how it was meant to work. For example, above those lines you mention, there's a different way of enabling colors,
xterm-color|*-256color) color_prompt=yes;;
Which makes me think that the colors could automatically enable if you had correct value in TERM variable.– JaakkoMar 26, 2020 at 18:02
I came up with this solution:
- open ~/.bashrc in an editor
copy this and add it at the end of .bashrc file:
PS1='\[\033[1;36m\]\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] '
save the file and restart bashrc:
source ~/.bashrc
For a full list of available colors and further options look up these links:
-
You might want to check out liquid prompt. It is a really info packed little prompt. google.com/… Aug 29, 2014 at 18:16
-
-
-
-
A version that is a bit more 'general' - should work with a varied environment:
(depends on terminfo)
Insert this in your $HOME/.bashrc
:
function fgtab {
echo "tput setf/setb - Foreground/Background table"
for f in {0..7}; do
for b in {0..7}; do
echo -en "$(tput setf $f)$(tput setb $b) $f/$b "
done
echo -e "$(tput sgr 0)"
done
}
# The prompt in a somewhat Terminal -type independent manner:
cname="$(tput setf 3)"
csgn="$(tput setf 4)"
chost="$(tput setf 2)"
cw="$(tput setf 6)"
crst="$(tput sgr 0)"
PS1="\[${cname}\]\u\[${csgn}\]@\[${chost}\]\h:\[${cw}\]\w\[${csgn}\]\$\[${crst}\] "
Then execute source ~/.bashrc
.
After that, fgtab
will display a color table with numbers. Those numbers are for tput setf n
and tput setb n
where 'n' is the number, 'f' stands for 'foreground' and 'b' stands for 'background' color.
tput sgr 0
will reset foreground and background colors to default.
And as you can see, changing the colors used for the prompt becomes really easy (just edit the same number in $HOME/.bashrc
as you wish).
Add an $(tput setb n)
in $cname
if you wish to have ALL of the prompt with background n.
-
-
ibm.com/developerworks/linux/library/l-tip-prompt more of the direct number crunching.– HannuAug 29, 2014 at 20:34
-
man 5 terminfo
shows whattput
can be used with, it is a bit technical though so "take heed" - but a bit of guessing and testing may actually let you get it working.– HannuAug 30, 2014 at 16:40
If you are using Termux then you can Install zshell which will change everything in your terminal, You can read this post fo the installation.https://www.learntermux.tech/2020/02/how-to-install-z-shell-best-theme-for-TERMUX-2020.html
-
1It is good to add the details of the answer from the link in your answer in case the link ever goes down.– gmanFeb 15, 2020 at 14:00
I've been having trouble making "force-color-prompt" to work in Ubuntu 20 using Kitty/Putty.
But notice the following code in the default Ubuntu 20 .bashrc file: case "$TERM" in xterm-color|*-256color) color_prompt=yes;; esac
So in Kitty, go to
- Connection
- Data
Then change "Terminal-type string" from "xterm" to "xterm-color" and viola!