Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prompt colouring #140

Closed
gallwood opened this issue Dec 31, 2018 · 9 comments
Closed

Prompt colouring #140

gallwood opened this issue Dec 31, 2018 · 9 comments

Comments

@gallwood
Copy link

Hi,

Not exactly a problem, but...

Is there a way of having the shell prompt (username@machine) a dirrent colour to the rest of the command line? Much like the standard wsl bash shell prompt?

Regards

Graham

@mintty
Copy link
Owner

mintty commented Jan 1, 2019

See man bash, section PROMPTING. Don't forget to embed escape sequences in \[...\]. See also #134.
This is a bash issue, not related to mintty.

@gallwood
Copy link
Author

gallwood commented Jan 1, 2019

Ah, I see. I'm a bit new to wsl :)

Interesting, if I invoke the bash shell from a windows command prompt then the prompt is coloured. If I start the bash shell through wsltty it is not.

I edited the .bashrc file in ~ and uncommented the force_color_prompt=yes variable.

Thanks for your patience.

@mintty
Copy link
Owner

mintty commented Jan 2, 2019

WSL in windows console is not coloured for me. You may have configured something already. Without any information about your environment, not even the WSL distribution, it is not possible to analyse this remotely.

@mintty mintty closed this as completed Jan 2, 2019
@LuKePicci
Copy link

LuKePicci commented Jan 28, 2019

I have the same issue, the prompt is coloured as per bash settings, and in fact when I open up a WSL console by either the default terminal emulator or the terminal emulator inside VS Code it works.
To be precise, it works with either wsl.exe, bash.exe, or ubuntu.exe.
However it is not when open it from WSLtty. Apart from the prompt, everything else appear coloured as expected.

.bashrc is set to enable prompt colors whenever the surrounding terminal emulator supports it, I can override this and forcefully apply colors, but it doesn't sound like the best approach.

My WSL distribution is the standard "ubuntu" package from the store, installed before 18.04 release, I never updated from 16 to 18. and it is not one of the available version specific packages currently available as "ubuntu 16.04" and "ubuntu 18.04" respectively.

@Biswa96
Copy link
Contributor

Biswa96 commented Jan 28, 2019

Which Windows 10 version do you use? Can you do a test? Create a user with adduser command, log in that user in wsltty, can you see the prompt colored text?

@mintty
Copy link
Owner

mintty commented Jan 28, 2019

And echo "$PS1" | od -t c -t x1 in both environments.

@LuKePicci
Copy link

LuKePicci commented Jan 28, 2019

@Biswa96 created a new testcolor user from standard terminal launching ubuntu.exe with:
sudo adduser testcolor
then launched wsl.bat, logged into as testcolor with:
sudo login
it logged in as testcolor but PS1 still gets set to the uncoloured prompt

I also added an echo coloring: $color_prompt in .bashrc of my main user immediately before it performs color support checking, and when I launch wlstty it shows that variable is empty, while it gets set to yes in both wsl default terminal and VS code built-in one. Seems like it gets set from upstream, maybe by the terminal emulator itself.

@mintty probably this will clarify what you were asking for

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color|*-256color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
        # We have color support; assume it's compliant with Ecma-48
        # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
        # a case would tend to support setf rather than setaf.)
        color_prompt=yes
    else
        color_prompt=
    fi
fi
echo coloring: $color_prompt
if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\$
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

@LuKePicci
Copy link

I think I've found the culprit, seems like $TERM is "xterm" in mintty, and "xterm-256color" in the working ones.

@LuKePicci
Copy link

So it is just a matter of default mintty settings, it has "xterm" where the default wsl one exposes itself as "xterm-256color". Now works as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants