Console-colours

From wikipost
Revision as of 16:21, 7 May 2020 by Admin (talk | contribs)
Jump to navigationJump to search

When working with Linux remotely over ssh it's sometimes nice to be able to work with a different colour scheme (or color scheme as some write). With ssh clients like Putty it's easy to change the foreground and background colours of the characters, but Linux supports different colours for different types of data; sometimes based on the file extension, sometimes based on functionality (e.g. directory names, command prompt, current working directory, bold text, links, etc..).

Below are listed the most commonly used colour sets and some instructions on how to change them.

change bash prompt colours

The bash prompt can show colors for username, hostname and current working directory.

The colours as well as the components that determine what the prompt should contain are all set in the PS1 environment variable.

The PS1 string is usually set in ~/.bashrc and can look something like this:

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

Pay attention at the part \u@\h it is saying “user@host” and the number before it \[\033[01;32m\] indicates the color. This is what you have to change.

The colors numbers are:

Black       0;30     Dark Gray     1;30
Blue        0;34     Light Blue    1;34
Green       0;32     Light Green   1;32
Cyan        0;36     Light Cyan    1;36
Red         0;31     Light Red     1;31
Purple      0;35     Light Purple  1;35
Brown       0;33     Yellow        1;33
Light Gray  0;37     White         1;37


change manpage colors

When man pages are viewed, they are piped through a program called ‘less’, which offers page navigation and search capabilities of the man-page text.

The idea is to override the colour settings that less uses.

edit and add the following lines to ~/.bashrc to load up the new colourscheme.

export LESS_TERMCAP_mb=$(printf '\e[01;31m') # enter blinking mode - red
export LESS_TERMCAP_md=$(printf '\e[01;35m') # enter double-bright mode - bold, magenta
export LESS_TERMCAP_me=$(printf '\e[0m') # turn off all appearance modes (mb, md, so, us)
export LESS_TERMCAP_se=$(printf '\e[0m') # leave standout mode    
export LESS_TERMCAP_so=$(printf '\e[01;33m') # enter standout mode - yellow
export LESS_TERMCAP_ue=$(printf '\e[0m') # leave underline mode
export LESS_TERMCAP_us=$(printf '\e[04;36m') # enter underline mode - cyan

The color codes are as follows:

    30 – black
    31 – red
    32 – green
    33 – orange
    34 – blue
    35 – magenta
    36 – cyan
    37 – white

Some other escape codes which you could use include:

    0 – reset/normal
    1 – bold
    3 – italic/reversed
    4 – underlined
    5 – blink


change vi (vim) colours

The vi editor has a range of color schemes available that are defined in /usr/share/vim/vim74/colors/

Adding:

colo blue

..to ~/.vimrc will use the ‘blue’ colorscheme. Other options are:

darkblue
default
delek
desert
elflord
evening
industry
koehler
morning
murphy
pablo
peachpuff
ron
shine
slate
torte
zellner

You could of course also type: ‘colo blue’ on the vi status line to immediately change to it.


Add the following line to your ~/.vimrc to change the bottom line text color (that shows the edit mode, INSERT or REPLACE):

hi ModeMsg term=bold ctermfg=2 gui=bold guifg=SeaGreen


When 'su' -ing into another account, the .vimrc of that su account will override the .vimrc from the account you were coming from.


More options:

"hi LineNr ctermfg=grey guifg=grey
"hi Statement ctermfg=black guifg=black
hi Identifier ctermfg=darkGreen guifg=darkGreen
hi Comment term=bold ctermfg=4 guifg=#406090
hi Constant term=underline ctermfg=Red guifg=#c00058
hi Special term=bold ctermfg=Blue guifg=SlateBlue
hi Identifier term=underline ctermfg=Black guifg=Black
hi Statement term=bold ctermfg=Brown gui=bold guifg=Brown
hi PreProc term=underline ctermfg=Magenta guifg=Magenta3
hi Type term=underline ctermfg=Green gui=bold guifg=SeaGreen
hi Ignore cterm=bold ctermfg=7 guifg=bg
hi Error term=reverse cterm=bold ctermfg=7 ctermbg=1 gui=bold guifg=White guibg=Red
hi Todo term=standout ctermfg=0 ctermbg=3 guifg=Blue guibg=Yellow

To see all the available (and currently configured color schemes) type the following:

hi