9

The TERM environment variable defaults to xterm so the .bashrc file does not provide full color in the shell by default.

How to I change the TERM environment variable to xterm-color for the gnome terminal emulator app only?

Update: By full color I mean changes the command prompt to use color in addition to displaying output such as directory listing in color too.

3
  • What do you mean by "does not Provide full color"? How many colors do you have in your terminal? How did you tested it?
    – A.B.
    Apr 27, 2015 at 8:11
  • .bashrc changes the PS1 prompt to color only if XTERM=xterm-color Apr 27, 2015 at 8:12
  • What is the output of tput colors.
    – A.B.
    Apr 27, 2015 at 8:12

2 Answers 2

10

There are two issues here.

One is how to detect if you're running inside gnome-terminal (or any other app using the same vte widget for the current terminal emulation). Assuming you're on a recent enough Ubuntu, the presence of the $VTE_VERSION variable tells you this. You could edit your .bashrc to contain something like

if [ -n "$VTE_VERSION" ]; then
    # Gnome-terminal and other vte3-based emulators
    color_prompt=yes
fi

The other issue is that for some reason Ubuntu's default .bashrc tries to look for xterm-color which is not really used nowadays. Either the standard xterm (which supports colors anyways), or the more modern xterm-256color are the popular choices, the default slowly moving towards the latter. (gnome-terminal changed its default from xterm to xterm-256color in 3.16, which is present in Ubuntu 15.10 beyond)

If you would like to move forward and already enjoy plenty of colors in several applications, I recommend that you already switch to TERM=xterm-256color, which you could also do in the if-branch above.

Ubuntu's .bashrc is obsolete for using xterm-color. I much rather recommend modifying these bits in the script around whatever $TERM you already have (xterm) or would prefer to have (maybe xterm-256color), rather than the other way around, modifying $TERM to match .bashrc's requirement.

1
  • 1
    Aware of xterm-color being outdated, I still think it’s a good idea to append -256color to $TERM, making the capability more explicit. Nov 15, 2020 at 23:00
6

For gnome-terminal

Edit the profile settings in gnome-termninal:

enter image description here

Replace /bin/bash with your shell command and use your parameter for TERM.

You can also edit the entries with dconf. Open a terminal and start dconf-editor:

dconf-editor

Open the entry org/gnome/terminal/legacy/profiles: and select your profile. Change the value for custom-command.

10
  • Having edited the profile setting using the screenshot, the terminal emulator app opens and closes and I'm not able to use it at all. Apr 27, 2015 at 8:27
  • The terminal closes again when you've made a bad record. For example, the wrong shell. Give me a second.
    – A.B.
    Apr 27, 2015 at 8:30
  • I have improved my answer, read the dconf-editor part.
    – A.B.
    Apr 27, 2015 at 8:37
  • Thanks. I finally found it under org.gnome.terminal.legacy.profile.* Apr 27, 2015 at 8:41
  • The second method using the .pam_environment didn't have any effect but I corrected a typo in the GUI box and now it appears to have taken effect upon launching the app. I will +1 your answer when I get enough reputation points. Thank you. Apr 27, 2015 at 8:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .