我正在通过 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"
Run Code Online (Sandbox Code Playgroud)
小智 35
/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 上的标准终端应用程序,以及您在 Mac 上的终端中使用的配置文件。
颜色停止工作,很可能是在您从Snow Leopard升级到Lion之后。
在 Lion 中,出于某种原因,默认情况下终端被声明为“ xterm-256color ”而不是“ xterm-color ”,这是 Ubuntu 所理解的。
其中一个办法是给你的,因为先前提到的反应,取消注释force_color_prompt=yes中~/.bashrc
另一种选择是在 Terminal.app 中将终端重新声明为 xterm-color。以下是如何做到这一点:
Settings选项卡并找到设置为默认的主题Advanced选项卡Declare terminal as:并将其设置为xterm-color这是我的设置
更新:似乎Mountain Lion从下拉菜单中完全删除了xterm-color选项。如果您正在进行升级,您很可能会保留旧配置,但如果您进行全新安装,则必须手动编辑终端的配置文件,为此您需要一个 plist 编辑器(包含在需要的XCode中)通过 App Store 安装)。终端文件的位置在~/Library/Preferences/com.apple.Terminal.plist为了添加xterm-color选项,请执行以下操作:
$ open ~/Library/Preferences/com.apple.Terminal.plistRoot > Window SettingsTerminalType密钥。TerminalType键更改为xterm-color| 归档时间: |
|
| 查看次数: |
93762 次 |
| 最近记录: |