Léa-Linux & amis :   LinuxFR   GCU-Squad   GNU
Couleur console
Envoyé par: Erucia

bonjour,

Je cherche à mettre de la couleur dans ma console et je sais que ça a un rapport avec un fichier nommé dir_colors et le bash.bashrc mais je n'y arrive toujours pas. Quelqu'un pourrait-il m'aider ?

Poste le Monday 20 August 2007 09:40:22
Répondre     Citer    
Re: Couleur console
Envoyé par: francoisp

exempel de mise en couleurs du prompt (.bashrc)
et du ls coloré (.bashrc aussi)
#PS1="\[\033[1;34m\][\$(date +%H:%M)][\u@\h:
#\w]$\[\033[0m\] "

function prompt {
local GRAD1=`tty|cut -d/ -f3`
local COLOR1="\[\033[1;34m\]"
local COLOR2="\[\033[0;34m\]"
local COLOR3="\[\033[1;30m\]"
local COLOR4="\[\033[0m\]"
PS1="$COLOR3.$COLOR1.$COLOR2($COLOR1\u$COLOR3@$COLOR1\h$COLOR2)$COLOR1.$COLOR2($COLOR1\#$COLOR3/$COLOR1$GRAD1$COLOR2)$COLOR1.$COLOR2($COLOR1\$(date +%H:%M)$COLOR3:$COLOR1\$(date +%m/%d/%y)$COLOR2)$COLOR1.$COLOR3-$COLOR4\n$COLOR3.$COLOR1.$COLOR2($COLOR1\$$COLOR3:$COLOR1\w$COLOR2)$COLOR1.$COLOR3-$COLOR4 "
PS2="$COLOR2.$COLOR1.$COLOR3-$COLOR4 "
}

prompt

alias emacs="emacs -bg black -fg white"
alias e=emacs
alias ls="ls --color"
alias l=ls
alias ll="ls -al"

TERM=xterm

export TERM

les variables d'environnement qui définissent la couleur autres que PS*
COLORS=/etc/DIR_COLORS
LS_COLORS='no=00:fi=00:di=01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01yawning smileyr=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01;35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:'
                    ls --color -l $fichier >>/tmp/mail_fichier_corps.$$ 2>&1;
    local COLOR1="\[\033[1;34m\]";
    local COLOR2="\[\033[0;34m\]";
    local COLOR3="\[\033[1;30m\]";
    local COLOR4="\[\033[0m\]";

un exemple de DIR_COLORS :
# Configuration file for the color ls utility
# This file goes in the /etc directory, and must be world readable.
# You can copy this file to .dir_colors in your $HOME directory to override
# the system defaults.

# COLOR needs one of these arguments: 'tty' colorizes output to ttys, but not
# pipes. 'all' adds color characters to all output. 'none' shuts colorization
# off.
COLOR tty

# Extra command line options for ls go here.
# Basically these ones are:
#  -F = show '/' for dirs, '*' for executables, etc.
#  -T 0 = don't trust tab spacing when formatting ls output.
OPTIONS -F -T 0

# Below, there should be one TERM entry for each termtype that is colorizable
TERM linux
TERM console
TERM con132x25
TERM con132x30
TERM con132x43
TERM con132x60
TERM con80x25
TERM con80x28
TERM con80x30
TERM con80x43
TERM con80x50
TERM con80x60
TERM cons25
TERM xterm
TERM rxvt
TERM xterm-color
TERM color-xterm
TERM vt100
TERM dtterm
TERM color_xterm
TERM ansi
TERM screen

# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1

# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes: 
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00       # global default, although everything should be something.
FILE 00         # normal file
DIR 01;34       # directory
LINK 01;36      # symbolic link
FIFO 40;33      # pipe
SOCK 01;35      # socket
BLK 40;33;01    # block device driver
CHR 40;33;01    # character device driver
ORPHAN 01;05;37;41  # orphaned syminks
MISSING 01;05;37;41 # ... and the files they point to

# This is for files with execute permission:
EXEC 01;32 

# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
.cmd 01;32 # executables (bright green)
.exe 01;32
.com 01;32
.btm 01;32
.bat 01;32
.sh  01;32
.csh 01;32
.tar 01;31 # archives or compressed (bright red)
.tgz 01;31
.arj 01;31
.taz 01;31
.lzh 01;31
.zip 01;31
.z   01;31
.Z   01;31
.gz  01;31
.bz2 01;31
.bz  01;31
.tz  01;31
.rpm 01;31
.cpio 01;31
.jpg 01;35 # image formats
.gif 01;35
.bmp 01;35
.xbm 01;35
.xpm 01;35
.png 01;35
.tif 01;35

pour le reste tu as le man page de bash et de ls


Poste le Tuesday 21 August 2007 07:13:32
Répondre     Citer    
Re: Couleur console
Envoyé par: Erucia

Merci francoisp de m'avoir répondu.

Donc si j'ai bien compris pour mettre de la couleur au terminal (prompt c'est ça ?) je dois bidouiller le fichier .bahsrc et le dir_color c'est pour le ls.

Bon je vais essayer ça de suite.

Encore merci

Poste le Tuesday 21 August 2007 08:25:41
Répondre     Citer    
Re: Couleur console
Envoyé par: Erucia

Bon j'ai testé ça marche plus ou moins. D'abord j'ai oublié de préciser que je suis sous debian etch.

Bon en fait je cherche a colorier mon prompt car je me suis habituée aux couleurs au boulot ou la couleur de fond du prompt est noir, les fichiers de conf en jaune, les respertoires en vert etc...

Seulement je pensais simplement copier le /etc/bash.bashrc et le /etc/dir_colors du pc du boulot (sous sarge) pour le mettre sur mon pc. Seulement voilà, ça ne fonctionne pas.

voici, le bash.bashrc et le dir_colors du boulot, pouvez vous me dire pourquoi ça ne marche pas ?

bash.bashrc

# System-wide .bashrc file for interactive bash(1) shells.

# To enable the settings / commands in this file for login shells as well,
# this file has to be sourced in /etc/profile.

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" -a -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color)
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

# enable bash completion in interactive shells
#if [ -f /etc/bash_completion ]; then
#    . /etc/bash_completion
#fi

et le dir_colors

# /etc/dir_colors ou ~/.dir_colors
# Fichier de configuration des couleurs pour la commande 'ls'
# Formation Debian GNU/Linux par Alexis de Lattre
# [www.via.ecp.fr]

# Les couleurs sont exprimées sous forme d'une liste de numéros
# séparés par des points-virgules, sachant qu'il ne doit pas y
# avoir plus d'un numéro par catégorie.

# Il existe 3 catégories :
# - Type :
#   00=normal 01=gras 04=souligné 05=clignotant 07=inversé caractères/fond
#   08=invisible (?)
# - Couleur des caractères :
#   30=noir 31=rouge 32=vert 33=jaune 34=bleu 35=magenta 36=cyan 37=blanc
# - Couleur du fond
#   40=noir 41=rouge 42=vert 43=marron 44=bleu 45=magenta 46=cyan 47=gris

# Couleur par défaut globale
NORMAL 00
# Couleur par défaut pour les fichiers
FILE 00
# Couleur pour les répertoires
DIR 01;32
# Couleur pour les liens symboliques
LINK 36
# Couleur pour les FIFOs
FIFO 33
# Couleur pour les sockets
SOCK 01;35
# Couleur pour les block device drivers
BLK 01;33
# Couleur pour les character device drivers
CHR 01;33
# Couleur pour les fichiers ayant les permissions d'exécution
EXEC 01;31

# Couleur pour les fichiers selon leur extension

# Fichiers de configuration
.conf 01;33
# Fichiers exécutables
.sh   01;31
.pl   01;31
.php3 01;31
.php  01;31
# Fichiers compressés
.tar  34
.tgz  34
.arj  34
.taz  34
.lzh  34
.zip  34
.gz   34
.bz2  34
.rar  34
# Packages
.deb  33
.rpm  33
# Fichiers images
.jpg  35
.JPG  35
.jpeg 35
.eps  35
.gif  35
.png  35
.bmp  35
.xpm  35
.tif  35
.tiff 35
.tga  35
.pcx  35
# Fichiers audio/vidéo
.avi  32
.mpg  32
.mpeg 32
.vob  32
.au   32
.wav  32
.mp3  32
.ogg  32

Poste le Tuesday 21 August 2007 09:48:46
Répondre     Citer    

Veuillez vous authentifier auparavant pour commenter.

 

Ce forum !
Couleur console
Un problème avec une commande du shell ? Comment utiliser la crontab ? Vous avez des soucis pour la gestion réseau sous Linux ? Pour vous la gestion des utilisateurs/groupes est du chinois ? Etc... Posez donc vos questions ici.

Sauf mention contraire, les documentations publiées sont sous licence Creative-Commons