端子颜色不起作用


30

我正在从OSX通过SSH访问Ubuntu 10.04.2 LTS服务器。最近,颜色停止工作了。我认为这是在我安装RVM或对其进行故障排除时发生的,但我并不乐观。

在.bashrc中,我不知所措force_color_prompt=yes,当我运行时,env | grep TERM我得到了TERM=xterm-color。但是仍然没有颜色。

有任何想法吗?谢谢!

这是输出 cat .bashrc

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

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

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

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

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# 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=
    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

# 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 -alF'
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

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

[[ -s "/usr/local/rvm/scripts/rvm" ]] && . "/usr/local/rvm/scripts/rvm"

嗨!cat ~/.bashrc请在您的问题中添加的输出!
antivirtel

Answers:


29

/ etc / skel中有一个默认的示例.bashrc文件-您可以使用当前的.bashrc进行备份,mv .bashrc .bashrc.bak然后cp /etc/skel/.bashrc .bashrc将该示例复制回到主目录。之后,取消注释force_color_prompt=yes新文件,然后将其添加[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"回文件的末尾(最后一行),以使RVM仍然有效。

之后,. .bashrc在提示符下执行以重新加载bash配置文件,这将再次为您提供彩色提示,并使用type rvm | head -1应返回文本的命令测试RVM :rvm is a function

如果这不起作用,请让我们知道您是否在Mac OS X上使用标准的Terminal应用程序,以及在Mac的Terminal中使用的配置文件。


对我有用,Xubuntu 13.04
绿色

9

颜色停止工作了,很可能是在您从Snow Leopard升级到Lion之后。

在Lion中,由于某种原因,默认情况下将终端声明为“ xterm-256color ”,而不是Ubuntu理解的“ xterm-color ”。

如先前的响应者所述,其中一种选择适合您,请force_color_prompt=yes~/.bashrc

另一个选项是在Terminal.app中将终端重新声明为xterm-color。这样做的方法如下:

  1. 启动Terminal.app
  2. 转到菜单终端->首选项(或使用Cmd +,)
  3. 转到Settings选项卡,找到设置为默认主题
  4. 转到Advanced标签
  5. 找到旁边的下拉菜单Declare terminal as:并将其设置为xterm-color

这是我的设置

更新:看来Mountain Lion从下拉菜单中完全删除了xterm-color选项。如果要进行升级,则很可能会保留原来的配置,但是如果要进行全新安装,则必须手动编辑Terminal的配置文件,为此,您将需要plist编辑器(包含在XCode中,通过App Store安装)。终端文件的位置在〜/ Library / Preferences / com.apple.Terminal.plist中,以便添加xterm-color选项,请执行以下操作:

  1. 如果当前正在运行,请退出Terminal.app
  2. 从App Store安装XCode(如果已经安装,请跳过此步骤)
  3. $ open ~/Library/Preferences/com.apple.Terminal.plist
  4. 导航至 Root > Window Settings
  5. 找到默认主题的名称(在我的情况下为Pro),将其展开并找到TerminalType键。
  6. 现在只需手动将TerminalType密钥更改为xterm-color
  7. 保存文件并启动终端。

1
nano ~/.bashrc

输入Ctrl+ W并搜索force_color,第一个结果应f在一个#字符之后突出显示。

Backspace现在Ctrl+ X,然后Y进行Yes,然后Enter

source ~/.bashrc

要么

. ~/.bashrc

现在,您将在终端中看到颜色。

希望这对您有用。



0

您可以尝试在Linux上更改.bashrc以将xterm-256color识别为颜色客户端,而不是试图迫使macOS Terminal将TERM报告为较旧的xterm-color。这似乎是Ubuntu较新版本的默认设置。为此,请更改以下行:

xterm-color) color_prompt=yes;;

至:

xterm-color|*-256color) color_prompt=yes;;

然后运行source .bashrc,您的终端将以彩色显示。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.