using gnome-terminal ( default ) and added below in ~/.bashrc
to colorize the terminal
# should be on the output of commands, not on the prompt
46# force_color_prompt=yes
47
48 if [ -n "$force_color_prompt" ]; then
49 if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
50 # We have color support; assume it's compliant with Ecma-48
51 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
52 # a case would tend to support setf rather than setaf.)
53 color_prompt=yes
54 else
55 color_prompt=
56 fi
57 fi
58
59 RED='\[\033[01;31m\]'
60 YELLOW='\[\033[01;33m\]'
61 GREEN='\[\033[01;32m\]'
62 BLUE='\[\033[01;34m\]'
63
64 CYAN='\[\033[01;36m\]'
65 LIGHT_CYAN='\[\033[00;36m\]'
66 WHITE='\[\033[00m\]'
67 LIGHT_GRAY='\[\033[01;37m\]'
68 COLOR_NONE='\[\e[00m\]'
69
70
71 parse_git_branch () {
72 while read -r branch; do
73 [[ $branch = \** ]] && current_branch=${branch#* }
74 done < <(git branch 2>/dev/null)
75 [[ $current_branch ]] && printf '(%s)' "$current_branch"
76 }
77
78
79 if [ "$color_prompt" = yes ]; then
80 #PS1='${debian_chroot:+($debian_chroot)}\[\033[00m\]\t \[\033[01;37m\]\u@\[\033[01;36m\]\h\[\033[01;33m\]:\[\033[00;32m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ '
81 PS1="${debian_chroot:+($debian_chroot)} \\[$(tput setaf 2)\\]\t ${LIGHT_GRAY}\u@\h${GREEN}:${BLUE}\w${RED} $(parse_git_branch)${WHITE}$ "
82 else
83 PS1="${debian_chroot:+($debian_chroot)}\t${LIGHT_GRAY}\u@\h${GREEN}:\w$(parse_git_branch)\$ "
84 fi
85 PS1="$PS1${RED}"
86
87 unset color_prompt force_color_prompt
but it does not who host and username diffrent color as defined while dir and command are colored as defined
what could be the issue here?
Note: if comment line # 87 unset color-prompt forced-color-prompt
then branches name are not getting dispalyed in shell
see the attached screenshot below
so How can we enable the color for the host/username also?
Undo the addtions you made to line #83, leaving in just the git branch name; this is the prompt that is meant to be shown in case the terminal has no color support:
Then set your color prompt in line #81; for the purpose of the example, I'm setting the username to yellow, the
@
to white and the hostname to cyan (I will use${GREEN}
instead of\\[$(tput setaf 2)\\]
to mantain consistency with the rest of the prompt):You may consider swapping ANSI color escape codes for
tput
commands to achieve better compatibility across different terminals on systems wheretput
is installed, at the cost of a slight overhead.