我有一个丰富多彩的bash终端(例如ls和vim在配置时显示颜色)。
通过ssh连接到远程服务器时,如何显示这些颜色?
我有一个丰富多彩的bash终端(例如ls和vim在配置时显示颜色)。
通过ssh连接到远程服务器时,如何显示这些颜色?
Answers:
阅读“ Beyond Linux From Scratch”一书中的dircolors.sh小节:
该脚本使用
~/.dircolors
和/etc/dircolors
文件控制目录列表中文件名的颜色。它们控制ls --color之类的东西的彩色输出。本节末尾将介绍如何初始化这些文件。cat > /etc/profile.d/dircolors.sh << "EOF" # Setup for /bin/ls and /bin/grep to support color, the alias is in /etc/bashrc. if [ -f "/etc/dircolors" ] ; then eval $(dircolors -b /etc/dircolors) if [ -f "$HOME/.dircolors" ] ; then eval $(dircolors -b $HOME/.dircolors) fi fi alias ls='ls --color=auto' alias grep='grep --color=auto' EOF
结合使用/unix/9883/how-can-i-run-a-script-immediately-after-connecting-via-ssh和nik的答案,您可以执行以下操作:
ssh host.example.com -t '. /etc/profile; . ~/.profile; /bin/bash'
这将在登录时执行您的配置文件脚本,然后打开一个bash shell。您的配置文件脚本是定义颜色的地方。
或者,为了最大程度的方便,将以下内容添加到~/.ssh/config
文件中:
Host *
LocalCommand . /etc/profile; . ~/.profile; /bin/bash