não pode ativar a cor de aviso no terminal bash

0

Não consigo ativar a cor de aviso no meu terminal (ubuntu 14.04 LTS).

Aqui está o meu .bashrc:

force_color_prompt=yes
export LANGUAGE='en_US.UTF-8 git'

export HISTCONTROL=ignoreboth
#export HISTSIZE=100000
#export HISTFILESIZE=100000

# Eternal bash history.
# ---------------------
# Undocumented feature which sets the size to "unlimited".
# http://stackoverflow.com/questions/9457233/unlimited-bash-history
export HISTFILESIZE=
export HISTSIZE=
export HISTTIMEFORMAT="[%F %T] "
# Change the file location because certain bash sessions truncate .bash_history file upon close.
# http://superuser.com/questions/575479/bash-history-truncated-to-500-lines-on-each-login
export HISTFILE=~/.bash_eternal_history
# Force prompt to write history after every command.
# http://superuser.com/questions/20900/bash-history-loss
PROMPT_COMMAND="history -a; $PROMPT_COMMAND"
# #########

# Some example functions
# function settitle() { echo -ne "\e]2;$@\a\e]1;$@\a"; }
export PATH=${PATH}:/home/louisro/android-sdk-linux/tools
export PATH=${PATH}:/home/louisro/android-sdk-linux/platform-tools
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export PATH=${JAVA_HOME}/bin:$PATH
export PATH=/usr/local/bin:$PATH

export NVM_DIR="/home/louisro/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"  # This loads nvm

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
    
por Louis 22.10.2015 / 11:54

2 respostas

3

Isso ativará a cor e também ativará a cor para alguma saída, como para a saída de make e ls.

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "3]0;${USER}@${HOSTNAME}: ${PWD}
. ~/.bashrc
7"' ;; *) ;; esac # set variable identifying the chroot you work in (used in the prompt below) if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac # 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=yes fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[3[01;32m\]\u@\h\[3[00m\]:\[3[01;34m\]\w\[3[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 # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' alias dir='dir --color=auto' alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # some more ls aliases alias ll='ls -l' alias la='ls -A' alias l='ls -CF' # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi make() { /usr/bin/make "$@" 2>&1 | sed -E -e "s/error/ $(echo -e "\033[31m" ERROR "\033[0m"/g)" -e "s/warning/ $(echo -e "\033[0;33m" WARNING "\033[0m"/g)" return ${PIPESTATUS[0]} }

Fonte do seu arquivo ~/.bashrc para aplicar as alterações:

# Commented out, don't overwrite xterm -T "title" -n "icontitle" by default.
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PROMPT_COMMAND='echo -ne "3]0;${USER}@${HOSTNAME}: ${PWD}
. ~/.bashrc
7"' ;; *) ;; esac # set variable identifying the chroot you work in (used in the prompt below) if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac # 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=yes fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[3[01;32m\]\u@\h\[3[00m\]:\[3[01;34m\]\w\[3[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 # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ]; then test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)" alias ls='ls --color=auto' alias dir='dir --color=auto' alias vdir='vdir --color=auto' alias grep='grep --color=auto' alias fgrep='fgrep --color=auto' alias egrep='egrep --color=auto' fi # some more ls aliases alias ll='ls -l' alias la='ls -A' alias l='ls -CF' # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. if [ -f ~/.bash_aliases ]; then . ~/.bash_aliases fi make() { /usr/bin/make "$@" 2>&1 | sed -E -e "s/error/ $(echo -e "\033[31m" ERROR "\033[0m"/g)" -e "s/warning/ $(echo -e "\033[0;33m" WARNING "\033[0m"/g)" return ${PIPESTATUS[0]} }
    
por mchid 22.10.2015 / 12:51
3

Eu acho que você não definiu uma cor para o seu prompt. Você pode fazer isso com a seguinte sintaxe: \e[x;ym $PS1 \e[m

\e[ : Start colour scheme.
x;y : Colour pair to use (x;y)
$PS1 : Your shell prompt variable.
\e[m : Stop colour scheme.

Para definir um prompt de cor vermelha, digite o seguinte comando:

export PS1="\e[0;31m[\u@\h \W]\$ \e[m "

adicione-o ao seu .bashrc para torná-lo permanente.

Aqui está uma lista de cores disponíveis:

Colour  Code
Black   0;30
Blue    0;34
Green   0;32
Cyan    0;36
Red     0;31
Purple  0;35
Brown   0;33
Blue    0;34
Green   0;32
Cyan    0;36
Red     0;31
Purple  0;35
Brown   0;33

Nota: você precisa substituir o dígito 0 por 1 para obter uma versão de cor clara. consulte este tutorial para mais informações. Você também pode dar uma olhada nesta explicação alemã muito boa

    
por Wayne_Yux 22.10.2015 / 12:45