如何在FreeBSD / cshrc上给提示着色? [英] How to color a prompt on FreeBSD/cshrc?

查看:85
本文介绍了如何在FreeBSD / cshrc上给提示着色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要负责管理一堆服务器,我想在每个服务器上都设置提示,这样我就不会对登录位置感到困惑。



我已经编辑了 .cshrc 文件并将其放入其中:

 设置提示=`whoami @@主机名-s :: $ cwd'$'

但是我想为提示涂上颜色,使其更加突出。也许绿色带有白色文本或其他内容。我怎样才能做到这一点?我对shell语法不是很熟悉。



我从Ubuntu随附的标准终端中通过SSH输入(如果相关)。

解决方案



(来源: funtoo.org



例如, Hello World以粗体显示,青色红色背景为%{\e [36; 41; 1m%} Hello World%{\e [0m%}


I'm being put in charge of managing a bunch of servers, I want to set up my prompts on each of them so that I don't get confused as to where I am logged in to.

I've edited my .cshrc files and put this in them:

set prompt=`whoami`@`hostname -s`:$cwd'$ '

But I'd like to color that prompt so it stands out a bit more. Maybe green with white text or something. How can I do that? I'm not very familiar with the shell syntax.

I'm SSH-ing in from the standard terminal that comes with Ubuntu, if that's relevant.

解决方案

This page has a pretty good explanation, although the syntax is a bit different in csh. Here's what I came up with:

set prompt="%{\e[32;1m%}%n%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%~%{\e[37m%}"\$"%{\e[0m%} "
# root variation:
set prompt="%{\e[31;1m%}root%{\e[37m%}@%{\e[33m%}%m%{\e[37m%}:%{\e[36m%}%/%{\e[37m%}#%{\e[0m%} "

update: the previous prompt I had here didn't actually update when you changed directories. using %n, %~ and %m instead of $cwd or pwd actually update. see here.

%{ ... %} means the stuff between should take 0-width
\e[ ... m specifies the colors and bolding. \e escapes the [ which seems to be necessary (I believe it's equivalent to \033), the m signifies the end.

Use 0 as your color to reset to default.

If you want to set a color and background, simply separate the numbers with semi-colons. Use 1 to enable bolding.

Consult this table to choose your colors:


(source: funtoo.org)

So for example, "Hello World" in bold, cyan on a red background would be %{\e[36;41;1m%}Hello World%{\e[0m%}

这篇关于如何在FreeBSD / cshrc上给提示着色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆