Estilizando o PROMPT da console (com uso de cores) | DeServ – Info
Lomadee, uma nova esp閏ie na web. A maior plataforma de afiliados da Am閞ica Latina.

Estilizando o PROMPT da console (com uso de cores)

By Fl谩vio Silva

Para quem gosta de trabalhar com a console (modo texto) em ambiente Unix e utiliza a shell BASH talvez essa dica seja de interesse. O BASH permite que apar锚ncia do prompt seja personalizada “a gosto do cliente”. E isso 茅 feito atrav茅s da v谩riavel de ambiente PS1. Experimente, por exemplo, informar o seguinte comando:

 PS1=[teste]:

Isso ir谩 imediatamente alterar a apar锚ncia do prompt. Para mant锚-lo assim todas as vezes que logar, basta definir essa vari谩vel apropriadamente em alguns do arquivos de inicializa莽茫o (.profile, .bashrc, .bash_profile).

Existem alguns meta-caracteres que permitem que certas informa莽玫es sejam apresentadas no prompt, veja a seguir a rela莽茫o deles extraida de “man bash”.

Eu costumo fazer com que meu prompt mostre as horas e o diret贸rio que estou localizado atualmente. Gosto tamb茅m de usar cores para deix谩-lo mais chamativo. Fa莽o isso usando o meta-caracter \nnn, com os seguinte valor para especificar que estarei trabalhando com c贸digos ANSI – coisa que utilizava muito quando mantinha um BBS.

   \033[<bg-color>;<fg-color>m

Sendo <bg-color>:

   40   -> preta
   41   -> vermelha
   42   -> verde
   43   -> marrom
   44   -> azul
   45   -> mangenta
   46   -> ciana
   47   -> cinza

e <fg-color>:

   30   -> preta
   31   -> vermelha
   32   -> verde
   33   -> marrom
   34   -> azul
   35   -> magenta
   36   -> ciana
   37   -> cinza

A t铆tulo de exemplo, experimente a seguinte combina莽茫o:

  PS1=\033[47;30m[\033[47;31mDebian\033[47;30m] \t\033[0m\n\u@\h:\W\$

Segue uma refer脢ncia completa sobre os valores poss铆veis.

   \a     an ASCII bell character (07)
   \d     the  date  in  "Weekday  Month  Date" format (e.g., "Tue May 26")
   \e     an ASCII escape character (033)
   \h     the hostname up to the first `.'
   \H     the hostname
   \j     the number of jobs currently managed by  the shell
   \l     the  basename of the shell's terminal device name
   \n     newline
   \r     carriage return
   \s     the name of the shell, the basename of $0
          (the portion following the final slash)
   \t     the current time in 24-hour HH:MM:SS format
   \T     the current time in 12-hour HH:MM:SS format
   \@     the current time in 12-hour am/pm format
   \A     the current time in 24-hour HH:MM format
   \u     the username of the current user
   \v     the version of bash (e.g., 2.00)
   \V     the  release  of  bash, version + patchelvel (e.g., 2.00.0)
   \w     the current working directory
   \W     the basename of the current  working  directory
   \!     the history number of this command
   \#     the command number of this command
   \$     if  the effective UID is 0, a #, otherwise a $
   \nnn   the character corresponding to the octal number nnn
   \\     a backslash
   \[     begin a sequence of non-printing characters,
          which could be used to embed a terminal con颅
          trol sequence into the prompt
   \]     end a sequence of non-printing characters

Tags: , ,

Deixe uma Resposta