Kitty terminal: I don't have any colors on PS1 bash prompt

Unlike other terminal emulators with kitty terminals I have no colors on bash prompt.
I am using ubuntu, my PS1 is [e]0;u@h: wa]${debian_chroot:+($debian_chroot)}u@h:w$

What have I to setup for this?

Thanks

Asked By: res1

||

I think it will work with the following code in your ~/.bashrc

I don’t know if you need to tamper with the variable TERM, but it is there in my
~/.bashrc. I borrowed it years ago, and don’t know/remember what is actually necessary.

if [ "${TERM:0:5}" == "xterm" ]
then
 typeset TERM=xterm-color  # force colour prompt
fi

function statstring {
RC=$?
  if [ "0" != $RC ]; then
    printf "[$RC] "
  fi
}
case "$TERM" in
xterm-color)
#    PS1='${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[00m]$ '

    if [ "$USER" = root ]; then
        PS1='[33[01;31m]$(statstring)[33[00m]${debian_chroot:+($debian_chroot)}[33[01;31m]u@h[33[00m] [33[01;34m]w[33[00m] $ '
    else
        PS1='[33[01;31m]$(statstring)[33[00m]${debian_chroot:+($debian_chroot)}[33[01;32m]u@h[33[00m] [33[01;34m]w[33[00m] $ '
    fi
    ;;
*)
    PS1='${debian_chroot:+($debian_chroot)}u@h:w$ '
    ;;
esac

if [ "$TERM" == "xterm-color" ]
then
 typeset TERM=xterm  # force basic prompt
fi

Explanation: ANSI escape sequences in PC computers start with ESC [ and in echo statements we can use 033 (ASCII: 3*8+3 = 27 for ESC). See this link for a detailed description of ANSI sequences.

There is also an ‘error code message’ when a command return with an error code. This is controlled by the function statstring.

enter image description here

Answered By: sudodus

Kitty may not be recognised as a color terminal…
What is the $TERM environment variable set to?

In gnome-terminal it says:

$ echo $TERM
xterm-256color

In kitty it says:

$ echo $TERM
xterm-kitty

Check your .bashrc for this line:

xterm-color|*-256color) color_prompt=yes;;

Add xterm-kitty to it, like this:

xterm-color|*-256color|xterm-kitty) color_prompt=yes;;

Now restart kitty.

Answered By: John Mee
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.