termcolours - Man Page

Automatically set unique terminal colour schemes

Synopsis

termcolours [--osc] [-P|-p] [-B|-b] [-D|-L] [-n] [-v] [hostname]

termcolours --xrdb [-P|-p] [-B|-b] [-D|-L] [-n] [-v] hostname ...; alias xterm="xterm -name xterm-`hostname`"

Description

Give terminals a persistent unique background colour, generated from the hostname (or some other string of your choosing).  Set the sixteen ANSI colours to contrast with the background, using shades from the Tango palette.

Options

hostname

The terminal background colour will be set based on a hash of the string hostname, somewhere between 0x000000 (black) and 0x404040 (dark), or 0xc0c0c0 (light) and 0xffffff (white).  Foreground colours are selected to contrast with the background.

Defaults to the current system hostname, if not specified.

--dry-run,  -n

Don't actually change the terminal colour.

--palette,  -p
--no-palette,  -P

Set (or don't set) the palette of 16 ANSI colours.  The default is to set them.

--background,  --bg,  -b
--no-background,  --no-bg,  -B

Set (or don't set) the background colour and contrasting foreground colour.  The default is to set them.

--is-dark,  -D

Exit 1 if the terminal is set to having a light background.

--is-light,  -L

Exit 1 if the terminal is set to having a dark background.

--bright-bold,  --no-bright-bold

Some terminals (notably XTerm), use bright colours by default for bold text.  If that's the behaviour you want/have, specify this option to flip the normal/bright colours.  This will provide better contrast for the default colours used by ls(1).

The default is that bold text is not bright.

When used in conjunction with the --xrdb option, the boldColors X resource will be set to match.

--osc

Set the colour scheme for the current terminal, by sending it control sequences.

This is the default behaviour.

--xrdb,  -x

Set the colour scheme for xterms started in the future, via X11 resources of the form XTerm-{argument}*vt100*foreground and XTerm-{argument}*vt100*background.

You must tell xterm which resource to look at, with something like:

    xterm -name "xterm-$HOSTNAME"
--verbose,  -v

Be more chatty.

--help,  -h

Displays brief help.

--man

Displays the full manual.

Examples

Make the output of journalctl, hostnamectl, systemctl, etc., legible on a terminal that has a light background

Add something like the following to your ~/.bash_profile:

    if termcolours --is-light; then
        export SYSTEMD_COLORS=auto-16
    fi

This requires systemd version 260 or higher (but won't make things any worse on earlier versions).  See "ENVIRONMENT" in systemd(1) for more information on the SYSTEMD_COLORS environment variable.

Set the prompt colour depending on the terminal colour

Add something like the following to your ~/.bash_profile:

    if termcolours --is-dark; then
        prompt_colour='37;100'
    else
        prompt_colour='30;107'
    fi
    PS1="\[\033[0;${prompt_colour}m\]\h:\W\\$\[\033[0m\] "

For a list of potential colour codes you could use here, see the Wikipedia page ANSI escape code <https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit>.

Set the background colour for a container, without having to install termcolours inside the container

Add the following to your ~/.bashrc:

    function docker {
        __termcolours_then_container "$FUNCNAME" "$@"
    }
    function podman {
        __termcolours_then_container "$FUNCNAME" "$@"
    }
    function __termcolours_then_container {
        declare -a args=("$@")

        if [[ "${args[1]}" == 'exec' || "${args[1]}" == 'run' ]]; then
            local arg
            local rc

            shift 2
            for arg in "$@"; do
                if [[ "$arg" != -* ]]; then
                   termcolours "$arg"
                   break
                fi
            done
        fi

        command "${args[@]}"
        rc=$?

        if [[ "${args[1]}" == 'exec' || "${args[1]}" == 'run' ]]; then
            termcolours
        fi

        return $rc
    }

Compatibility

The following terminal emulators are known to work.

Using OSC escape sequences

Full support

Partial support

Using X11 resources

  • XTerm (any version)

See Also

Author

Peter Oliver <mailto:terminalcolours@mavit.org.uk>

Licence

Copyright 2008, 2017, 2024-2026 Peter Oliver.

This program is part of termcolours.

termcolours is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

termcolours is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with termcolours. If not, see <https://www.gnu.org/licenses/>.

Info

2026-04-23 perl v5.42.2 User Contributed Perl Documentation