Grimoire-
Command
.es

GNU+Linux command memo

Colors in the console

Couleurs dans le terminal

1. Aliases

alias ls='ls --color=auto' (1)
alias vi='vim'
alias grep='grep --color' (2)
alias rgrep='rgrep -n --color' (2)
alias diff='colordiff' (3)
alias tail='colortail' (3)
alias make='colormake' (3) (4)

function wcolordiff () { wdiff -n $1 $2 | colordiff }
1 All the lines can be copie in your .zshrc or .bashrc
2 You may use rg instead, it’s natively using colors
3 You can install the color* command from corresponding Debian packages
4 Attention: using this alias stops zsh completion of Makefile targets

2. liquidprompt

Install the corresponding Debian package, then add the following lines to your .zshrc (or .bashrc) :

# Only load liquidprompt in interactive shells, not from a script or from scp
echo $- | grep -q i 2>/dev/null && . /usr/share/liquidprompt/liquidprompt

Source your config file or start a new terminal, you get a prompt that shows important information from your machine state : battery critical level, critical temperature or system load, the number of asleep jobs, the current git repository state or Python virtualenv loaded…

17:28:40 ⏚ ⌂69% 2z [:~/Wording … directory-path] [virtualenv-name] master(+11/-8)* 148 ±

Here you have : the time ; a symbol to recall that the laptop is plugged ; 69% of system load ; 2 sleeping processes ; the abregated working directory path ; the name of the loaded virtualenv ; git is on the master branch with some work to commit ; and a last process that ended with code 148 (which is what happen when you ; type CTRL+Z to pause a process)…

3. zsh plugins

3.1. zsh-syntax-highlighting

zsh-syntax-highlighting is a zsh plugin packaged in Debian (under that exact name). It gives to zsh typed commands a syntax coloration (for commands : existing or not, arguments : well formed or not…) comparable to fish 's one.

Once installed, you have to activate it via :

# Must be at the end of the .zshrc file
source /usr/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh

At the end of your .zshrc file.

3.2. zsh-autosuggestions

zsh-autosuggestions is a zsh plugin packaged in Debian. It automatically completes the current typed command with the matching last command, but in gray letters, after your cursor. You can accept this completion using the right arrow key.

To activate this plugin, add the following line in your .zshrc :

source /usr/share/zsh-autosuggestions/zsh-autosuggestions.zsh

3.3. colored-man-pages

To install this zsh plugin, clone the oh-my-zsh repository in your home :

$ git clone https://github.com/robbyrussell/oh-my-zsh.git

Then load oh-my-zsh adding this to the beginning of your .zshrc :

# Path to your oh-my-zsh installation.
export ZSH=/home/$user/.oh-my-zsh

And finally activate the plugin, adding its name in the plugins variable in (the middle of) your .zshrc :

plugins=( [plugins …] colored-man-pages)

4. colout, customize any command output

All at once and even more colout by Nojhan:

$ tail /var/log/boot.log | colout fail
$ tail /var/log/boot.log | colout "^.*fail.*$" red bold