One possibility, if the terminal supports it, is to use the terminal's Change Color escape sequence. Apparently konsole doesn't support it though. From the Xterm control sequence document (ctlseqs):
OSC Ps ; Pt BEL
Ps = 4 ; c ; spec -> Change Color Number c to the color specified by spec, i.e., a name or RGB specification as per XParseColor. Any number of c name pairs may be given. The color numbers correspond to the ANSI colors 0-7, their bright versions 8-15, and if supported, the remainder of the 88-color or 256-color table.
What this means is that the control sequence \e]4;NUMBER;VALUE\a
will change the appearance of color NUMBER. NUMBER is a color number (0–7 for the eight basic colors, 8–15 for the bright versions, and more if the terminal supports more colors). The VALUE is something that XParseColor understands, such as an RGB specification #123456
or an X color name (look for rgb.txt
on your machine, or use xcolors
to see the possibilities).
For example, the following command changes the basic blue color (color 4) and its bright variant (4+8) to contain some green:
printf '\033]4;4;#004080;12;#0040ff\007'
Note that this changes every character currently displayed in this particular color in the window. There is no way to change the meaning of a color only for subsequently displayed characters; if that's what you want, you'll have to configure each program displaying inside the terminal to use different color numbers when talking to the terminal.
Having this happen exactly when you're typing in an ssh session will be very complicated, but handling the common cases is reasonably simple: use a wrapper around ssh that changes the color palette, then runs ssh, and finally changes the color palette back. Examples of cases this won't handle are suspending the ssh process and running ssh inside screen or tmux.
Many online references often talk about color names that are not defined on my system
Those probably are defined, but they are X11 colors; once upon a time you could find them in /lib[64]/X11/rgb.txt
. In any case, this is a mapping of strings (e.g., dimgray
) to 24-bit RGB colors (e.g. 0xff8800
or #ff8800
, which would be orange). A 24-bit space is ~16 million colors, obviously X11 does not give them all names (CSS 3 uses X11 names, BTW).
The 24-bit space is used by your GUI; transparency is implemented by increasing this to a 32-bit space. However, git
isn't a GUI (G = graphical) tool, it's a TUI (T = terminal) tool, and it is limited to the colors available on a normal terminal.
I would like a solution that works for all distros, but primarily Debian
If you want this to be properly portable, you should rely only on the eight standard ANSI colors:
- black
- blue
- green
- yellow
- cyan
- white
- magenta
- red
A little disappointing next to the X11 list, but better than nothing at all! These also have a "bold" or "bright" version that is standard, making 16 colors, which you may be able to specify as, e.g., "brightyellow" (or conversely, "darkyellow").
Most GUI terminals1 have 256 color support and some terminal apps can exploit this. To test, you first need to set the $TERM
variable appropriately:
export $TERM=xterm-256color
Your terminal emulator may also have a configuration option for this. Colors under the xterm 256 color protocol are indexed:
The index number is in the bottom left corner. Notice the set at the bottom of this chart (0-15) is the 16 basic (bright and dark) ANSI colors. To reference one of these colors under the standard, you use color
+ the index number, eg. color40
.
1. A "GUI terminal" is a terminal emulator that runs in a GUI context, such as xterm, the GNOME terminal, etc. However, this does not make TUI apps (such as git) running in a GUI terminal into GUI apps. They are still TUI apps and are bound by that context.
Best Answer
The color palettes are all hard-coded so adding custom themes to gnome-terminal built-in Prefs Menu is not possible unless you are willing to patch the source code and recompile the application.
One way of setting a custom color themes for your profile is via scripts. Have a look at how solarize does it:
gnome-terminal-colors-solarized
Note, though, that gconf is EOL and future releases of gnome-terminal will use gsettings backend.