11

When I start gnome-terminal and do echo $TERM, I got xterm as output.

I want it to be xterm-256color

I've considered the solution to add 'export TERM=xterm256color' in my .bashrc. But I don't like this solution, what if I decide to switch shell? I have to add an other export to my new shell startup script?

So is there a better way to have automatically a 256 colors terminal when launching gnome-terminal?

13

Copying my answer from the same question @javabrett pointed out:

You were well advised not to change your startup scripts, specially ~/.bashrc. Any "terminal detection" using current $TERM or $COLORTERM in ~/.profile is merely a guess, and may, as you said, cause trouble when using other terminals (say, Putty or xterm). The terminal emulator is supposed to set $TERM, and this should not be changed from within the shell.

Gnome terminal, AFAIK, does not offer a configuration to change its TERM, but it does allow you to change your startup command, and that's all you need. Here is the trick:

Profile Preferences => Title and Command => Run a custom command instead of my shell

Then use the following command:

env TERM=xterm-256color /bin/bash

Just replace /bin/bash with your preferred shell if it's different. And no, you can't use "$SHELL" in that line for shell auto-detection ;) You have to hard-code it

5

Beginning with gnome-terminal version 3.16, it defaults to TERM=xterm-256color.

3
  • I'm on gnome terminal version 3.30 but it seem that TERM=xterm-256color is not the default. Explicitly specifying it with export TERM=xterm-256color does solve my question related to bracketed paste for example. – Paul Rougieux May 14 '20 at 15:20
  • TERM=xterm-256color is its default. If that's not what you see, either your shell initialization files tamper with it, or your distribution patches gnome-terminal (vte) to a different default. – egmont May 14 '20 at 17:53
  • Sorry that's because I was in a tmux session the $TERM variable then becomes screen. – Paul Rougieux May 15 '20 at 9:30
2

There's a good answer explaining how gnome-terminal doesn't allow TERM to be defaulted via its settings over at askubuntu.

It suggests that this is a compile-time option, so it appears that setting TERM in a shell profile or startup script is the best and only option. You might create a wrapper script or alias if you prefer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.