当我通过 ssh 连接到远程主机时,一切都只是一种字体/颜色。我想要像我在本地做的那样的颜色,例如绿色代表可执行文件,蓝色代表符号链接等。这样,当我在 ssh 主机上运行 $ git diff 时,它会显示我的颜色差异 =)
Dim*_*ima 39
因为它是服务器上的 xterm,所以我认为有问题 .bashrc
而且确实!ls --color=auto
仅当您连接到 TTY 时才有效。将所有内容更改为简单地--color
在.bashrc
远程主机上,现在一切都以漂亮的颜色呈现。
小智 32
这对我有用:
ssh -t my_host my_command
Run Code Online (Sandbox Code Playgroud)
-t
是关键。解释:
-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a
remote machine, which can be very useful, e.g. when implementing menu services. Multiple -t
options force tty allocation, even if ssh has no local tty.
Run Code Online (Sandbox Code Playgroud)
小智 22
似乎已经~/.bashrc
为我设置了颜色,问题是 ssh 不使用 bashrc 文件。您可以通过将以下内容添加到 ssh 会话中来使用 bashrc ~/.bash_profile
:
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
Run Code Online (Sandbox Code Playgroud)
小智 18
由于颜色在直接登录时工作正常,我只是取消force_color_prompt=yes
了文件中的行的注释~/.bashrc
,这也给了我 ssh 上的颜色:
# 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
Run Code Online (Sandbox Code Playgroud)
(Ubuntu 18.04 LTS)
小智 8
当您连接到服务器时,您的 XTERM 环境变量的内容是什么?
~ > export | grep -i term
TERM=xterm
Run Code Online (Sandbox Code Playgroud)
小智 6
就我而言,缺少的部分是有颜色的 ls、grep 等,可以通过向 .bashrc 文件添加别名来添加它们:
alias ls='ls --color=auto'
alias grep='grep --color=auto'
Run Code Online (Sandbox Code Playgroud)
ETC。
归档时间: |
|
查看次数: |
139940 次 |
最近记录: |