bash colorata

Da tempo avevo notato che la bash di Raspbian era colorata rispetto quella che avevo a disposizione sul server, la Raspbian era più recente e veniva da un’installazione del 2012 con un’opzione già abilitata, mentre sul server la vecchia installazione nasceva da una Lenny quando ancora era in testing e nel tempo si era persa qualcosa durante gli aggiornamenti.

Aprire il file .bashrc dell’utente desiderato e decommentare :

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

Per rendere efettive le modifiche aprire un nuovo terminale oppure:

$ source ~/.bashrc

Se non avete l’opzione disponibile, allora occorre inserire la parte completa.

Aprire il file .bashrc dell’utente desiderato e inserire:

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
  # We have color support; assume it's compliant with Ecma-48
  # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
  # a case would tend to support setf rather than setaf.)
  color_prompt=yes
    else
  color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\w \$\[\033[00m\] '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

Per rendere efettive le modifiche aprire un nuovo terminale oppure:

$ source ~/.bashrc

Possiamo anche personalizzare manualmente i colori inserendo una semplice riga all’inizio di .bashrc del’user e di root come negli esempi

  • Un prompt verde e blu per utenti normali:

puppa~/documenti $ sample output text

PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] \[\e[1;37m\]'
  • Un prompt rosso e blu per root:

root~/documenti $ sample output text

PS1='\[\e[0;31m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[0;31m\]\$ \[\e[m\]\[\e[0;37m\]'

Una lista dei colori :

# Regular Colors
Black='\e[0;30m'        # Nero
Red='\e[0;31m'          # Rosso
Green='\e[0;32m'        # Verde
Yellow='\e[0;33m'       # Giallo
Blue='\e[0;34m'         # Blu
Purple='\e[0;35m'       # Viola
Cyan='\e[0;36m'         # Ciano
White='\e[0;37m'        # Bianco

Link : Color Bash Prompt

 

PS. Dopo tanto tempo ho sostituito il mio glorioso Raspberry PI B+ con un nuovo Raspberry PI 3 B, e devo ammettere che il quad core fa la differenza in elaborazione contro il single core, ma la cosa che mi ha risolto molti problemi sulle prestazione è stato passare da 256MB a 1GB di RAM.

Rispondi

Questo sito usa Akismet per ridurre lo spam. Scopri come i tuoi dati vengono elaborati.