终端颜色不起作用

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

在.bashrc中我没有force_color_prompt=yes ,当我运行env | grep TERM 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" 

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

之后,执行. .bashrc . .bashrc在提示符下重新加载你的bash配置文件,它应该再次给你一个彩色提示并用命令type rvm | head -1测试RVM type rvm | head -1应该返回文本: rvm is a function

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

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

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

正如之前的响应者所提到的,其中一个选项force_color_prompt=yes~/.bashrc取消注释force_color_prompt=yes

另一种选择是将Terminal.app终端重新声明为xterm-color。 以下是如何做到这一点:

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

这是我的设置

更新Mountain Lion似乎完全从下拉菜单中删除了xterm-color选项。 如果你正在进行升级,你很可能会保留旧的配置,但是如果你正在进行全新安装,你将不得不手动编辑终端的配置文件,为此你需要一个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. 将plist导航到Root > Window Settings
  5. 找到默认主题的名称(在我的情况下是Pro)展开它并找到TerminalType键。
  6. 现在只需手动将TerminalType键更改为xterm-color
  7. 保存文件并启动终端。

如果您的主目录中尚不存在.bash_login文件,则可以选择.bash_login文件,并将.bashrc放入其中。

关闭终端并重新打开 – 您的问题应该解决!

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

 xterm-color) color_prompt=yes;; 

至:

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

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