Bash : personnaliser les couleurs de l'invite de commande (prompt) du terminal photo

Bash : personnaliser les couleurs de l’invite de commande (prompt) du terminal

Bash : réparer les tables MySQL en cas de crash photo

Lorsque l’on jongle avec différents serveurs et plusieurs fenêtres de terminal, il n’est pas toujours évident d’identifier immédiatement sur quelle machine on se trouve.

Pour remédier à ce problème, je vous propose de changer les couleurs de l’invite de commande (prompt) de votre terminal sous linux.

Editer le fichier .bashrc

Nous allons éditer le fichier .bashrc, qui permet d’éditer les préférences utilisateurs pour tout ce qui concerne bash:

nano .bashrcCode language: CSS (css)

Ajout de styles

Et voici quelques styles sympas à ajouter pour tuner votre prompt.

Style Lemon Lime

Ajoutez ceci à votre fichier .bashrc:

export PS1="\[$(tput bold)\]\[$(tput setaf 6)\]\t \[$(tput setaf 2)\][\[$(tput setaf 3)\]\u\[$(tput setaf 1)\]@\[$(tput setaf 3)\]\H \[$(tput setaf 6)\]\w\[$(tput setaf 2)\]]\[$(tput setaf 4)\]\\$ \[$(tput sgr0)\]"Code language: JavaScript (javascript)
Bash : personnaliser les couleurs de l'invite de commande (prompt) du terminal photo

C’est mon style préféré, très cocktail d’été. Voilà ce que cela donne:

Style Matrix

Vous pouvez aussi opter pour le style Matrix, tout vert:

export PS1="\[$(tput bold)\]\[$(tput setaf 2)\][\u@\h \W]\\$ \[$(tput sgr0)\]"Code language: JavaScript (javascript)

Style Rainbow

Ou encore pour un arc-en-ciel de couleurs :

export PS1="\[$(tput bold)\]\[$(tput setaf 1)\][\[$(tput setaf 3)\]\u\[$(tput setaf 2)\]@\[$(tput setaf 4)\]\h \[$(tput setaf 5)\]\W\[$(tput setaf 1)\]]\[$(tput setaf 7)\]\\$ \[$(tput sgr0)\]"Code language: JavaScript (javascript)

Personnalisation du prompt

Si vous souhaitez ajoutez des composants à votre prompt, voici quelques mots-clé utiles:

  • \u le nom de session utilisateur
  • \h le nom d’hôte jusqu’au premier ‘.’
  • \H le nom d’hôte complet
  • \n saut de ligne
  • \$ affiche le signe $ pour un simple utilisateur ou # pour l’utilisateur root
  • \\ un backslash “\”

Et voilà, un peu de couleur dans notre terminal !

Pearl Jam - Indifference photo 1

Pearl Jam – Indifference (waves)

Voici Indifference par Pearl Jam:

Intro: Em - Dsus4 - D (4x)

        Em                       D       Em             D 
I will light the match this mornin', so I won't be alone
   Em                  D         Em                 D
Watch as she lies silent, for soon light will be gone
   Em                       D          Em                 D
Oh, I will stand arms outstretched, pretend I'm free to roam
   Em                D            Em          D
Oh, I will make my way, through, one more day...alone...
  G          D                    Em - Em7
    How much difference does it make
  G          D                    Em - Em7 
    How much difference does it make, yeah...
    
     Em - Dsus4 - D

   Em               D         Em           D
I will hold the candle till it burns up my arm
   Em               D         Em                  D   
Oh, I'll keep takin' punches until their will grows tired
   Em               D         Em                 D
Oh, I will stare the sun down until my eyes go blind
    Em                 D           Em                D
Hey, I won't change direction, and I won't change my mind
   G            D               Em - Em7
     How much difference does it make
   G            D               Em - Em7   
Mmm, how much difference does it make..
     how much difference...

  Em - Dsus4 - D  
 
                Em       D          Em     D
I'll swallow poison, until I grow immune
         Em          D              Em           D        
I will scream my lungs out till it fills this roomCode language: PHP (php)

Très belle chanson.

Si de Rudyard Kipling, poème.

“If” – by Rudyard Kipling

If you can keep your head when all about you
Are losing theirs and blaming it on you,
If you can trust yourself when all men doubt you,
But make allowance for their doubting too;
If you can wait and not be tired by waiting,
Or being lied about, don’t deal in lies,
Or being hated, don’t give way to hating,
And yet don’t look too good, nor talk too wise:

If you can dream – and not make dreams your master;
If you can think – and not make thoughts your aim;
If you can meet with Triumph and Disaster
And treat those two impostors just the same;
If you can bear to hear the truth you’ve spoken
Twisted by knaves to make a trap for fools,
Or watch the things you gave your life to, broken,
And stoop and build ‘em up with worn-out tools:

If you can make one heap of all your winnings
And risk it on one turn of pitch-and-toss,
And lose, and start again at your beginnings
And never breathe a word about your loss;
If you can force your heart and nerve and sinew
To serve your turn long after they are gone,
And so hold on when there is nothing in you
Except the Will which says to them: ‘Hold on!’

If you can talk with crowds and keep your virtue,
‘ Or walk with Kings – nor lose the common touch,
if neither foes nor loving friends can hurt you,
If all men count with you, but none too much;
If you can fill the unforgiving minute
With sixty seconds’ worth of distance run,
Yours is the Earth and everything that’s in it,
And – which is more – you’ll be a Man, my son!

— Rudyard Kipling, “If”, 1895