Colorizing your incurable and also shell setting?

I invest a lot of my time operating in Unix settings and also making use of incurable emulators. I attempt to make use of shade on the command line, due to the fact that shade makes the result better and also instinctive.

What alternatives exist to add shade to my incurable setting? What methods do you make use of? What challenges have you run into?

However, assistance for shade differs relying on incurable type, OS, TERM setup, energy, buggy executions, and so on

. Below are some pointers from my arrangement, after a great deal of trial and error:

  1. I often tend to set TERM=xterm-color, which is sustained on the majority of hosts (yet not all).
  2. I work with a variety of various hosts, various OS variations, and so on. I make use of every little thing from macOS X, Ubuntu Linux, RHEL/CentOS/Scientific Linux and also FreeBSD. I'm attempting to maintain points straightforward and also common, when possible.
  3. I do a number of job making use of GNU screen, which includes an additional layer of enjoyable.
  4. Several OSs set points like dircolors and also by default, and also I do not intend to change this on a hundred various hosts. So I attempt to stick to the defaults. Rather, I fine-tune my terminal's shade arrangement.
  5. Usage shade for some Unix commands (ls, grep, less, vim) and also the Bash prompt. These commands appear to make use of the typical "ANSI escape sequences". As an example:

    alias less='less --RAW-CONTROL-CHARS'
    export LS_OPTS='--color=auto'
    alias ls='ls ${LS_OPTS}'

I'll upload my .bashrc and also address my very own inquiry Jeopardy Style.

2019-05-04 22:10:15
Source Share
Answers: 5

There's an excellent device for establishing your colours for the ls regulate -

2019-05-08 12:22:50

Set a bold/colored prompt. From and also the BashFAQ

# 'tput bold' will work regardless of the foreground and background colors.
# Place the tput output into variables, so they are only execd once.
bold=$(tput bold) # This could also be a color.
reset=$(tput sgr0)
export PS1="\[email protected]\[$bold\]\h\[$reset\]:\w \$ "

I've additionally taken care of to locate shade setups which are extensively sustained, and also which do not publish rubbish personalities in older settings (also FreeBSD4!), and also appears to function great if TERM = vt100, xterm, xterm - shade. (For the a lot of component). From my.bashrc :

# Set some options, based on the OS
OS=`uname -s` 

case "$OS" in
    "SunOS" ) 
        # Solaris ls doesn't allow color, so use special characters
        alias  ls='ls ${LS_OPTS}'
    "Linux" )
        # GNU ls supports colors!
        # See dircolors to customize colors
        export LS_OPTS='--color=auto' 
        alias  ls='ls ${LS_OPTS}'

        # Get color support for 'less'
        export LESS="--RAW-CONTROL-CHARS"

        # Use colors for less, man, etc.
        [[ -f ~/.LESS_TERMCAP ]] && . ~/.LESS_TERMCAP

        export GREP_OPTIONS="--color=auto"


        # Most FreeBSD & Apple Darwin supports colors
        export CLICOLOR=true
        # Get color support for 'less'
        export LESS="--RAW-CONTROL-CHARS"

        # Use colors for less, man, etc.
        [[ -f ~/.LESS_TERMCAP ]] && . ~/.LESS_TERMCAP

        export GREP_OPTIONS="--color=auto"
    * ) 
        echo "Unknown OS [$OS]"
2019-05-08 08:31:45

grep and also ls have actually currently been stated, if you desire a whole lot even more colors look into Generic Coloriser, its first objective was to colorize logfiles, yet right out of package it additionally colorizes ping, traceroute, gcc, make, netstat, diff, last, ldap, and also cvs.

It's conveniently expanded if you recognize regexes. I've included ps and also nmap to the checklist (if you get involved in grc I'll be greater than grateful to share the.conf apply for those 2 devices)

(Btw, to install it using synaptic, pacman, and also alike you could have far better good luck looking for "grc")

2019-05-08 06:12:08

Here are a number of points you can do :

Editors + Code
A great deal of editors have syntax highlighting assistance. vim and also emacs have it on by default. You can additionally enable it under .

You can additionally syntax emphasize code on the incurable by utilizing Pygments as a command - line device.

grep --color=auto highlights all suits. You can additionally make use of export GREP_OPTIONS='--color=auto' to make it relentless without a pen name. If you make use of --color=always, it'll use colour even when piping, which perplexes points.


ls --color=always

Colors defined by :

export LS_COLORS='rs=0:di=01;34:ln=01;36:mh=00:pi=40;33'

(tip : dircolors can be handy)

You can set your PS1 (shell prompt) to make use of colours. As an example :

PS1='\e[33;1m\[email protected]\h: \e[31m\W\e[0m\$ '

Will certainly generate a PS1 like :

[yellow ] lucas @ubuntu : [red ] ~ [regular ] $

You can get actually imaginative with this. As a suggestion :

PS1='\e[s\e[0;0H\e[1;33m\h    \t\n\e[1;32mThis is my computer\e[u[\[email protected]\h:  \w]\$ '

Places a bar on top of your incurable with some arbitrary details. (For ideal outcomes, additionally make use of alias clear="echo -e '\e[2J\n\n'".)

Removing Escape Sequences

If something is stuck outputting colour when you do not desire it to, I utilize this sed line to remove the retreat series :

sed "s/\[^[[0-9;]*[a-zA-Z]//gi"

If you desire an even more genuine experience, you can additionally remove lines beginning with \e[8m, which advises the incurable to hide the message. (Not extensively sustained.)

sed "s/^\[^[8m.*$//gi"

Additionally note that those ^ [s need to be real, actual ^ [s. You can type them by pushing ^ V ^ [ in bash, that is Ctrl + V, Ctrl + [.

2019-05-08 05:13:13

I additionally make use of :

export TERM=xterm-color
export GREP_OPTIONS='--color=auto' GREP_COLOR='1;32'
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

And also if you like colorizing your prompt, specified shade vars can be valuable :

export COLOR_NC='\e[0m' # No Color
export COLOR_WHITE='\e[1;37m'
export COLOR_BLACK='\e[0;30m'
export COLOR_BLUE='\e[0;34m'
export COLOR_LIGHT_BLUE='\e[1;34m'
export COLOR_GREEN='\e[0;32m'
export COLOR_LIGHT_GREEN='\e[1;32m'
export COLOR_CYAN='\e[0;36m'
export COLOR_LIGHT_CYAN='\e[1;36m'
export COLOR_RED='\e[0;31m'
export COLOR_LIGHT_RED='\e[1;31m'
export COLOR_PURPLE='\e[0;35m'
export COLOR_LIGHT_PURPLE='\e[1;35m'
export COLOR_BROWN='\e[0;33m'
export COLOR_YELLOW='\e[1;33m'
export COLOR_GRAY='\e[0;30m'
export COLOR_LIGHT_GRAY='\e[0;37m'

And afterwards my prompt is something similar to this :

case $TERM in
         local TITLEBAR='\[\033]0;\u ${NEW_PWD}\007\]'
         local TITLEBAR=""

local UC=$COLOR_WHITE               # user's color
[ $UID -eq "0" ] && UC=$COLOR_RED   # root's color

PS1="$TITLEBAR\n\[${UC}\]\u \[${COLOR_LIGHT_BLUE}\]\${PWD} \[${COLOR_BLACK}\]\$(vcprompt) \n\[${COLOR_LIGHT_GREEN}\]→\[${COLOR_NC}\] "  

$ (vcprompt) is calling a python manuscript in my ~/ sbin which publishes variation control details concerning the existing course. It consists of assistance for Mercurial, Git, Svn, Cvs, etc The writer of the manuscript has the source here.

Bash prompt screenshot

This is the full source of my prompt arrangement :

2019-05-08 04:21:33