-->

如何将图标添加到bash提示符(How to add an icon to the bash pro

2019-08-02 23:14发布

我知道你可以在你的〜/ .bashrc文件编辑PS1变量永久编辑bash提示符,矿山看起来是这样的:

PS1="\[\e[0;31m\]<HERP(._.)DERP>\[\e[0;0m\]";

但是你能在那里设置一个小小的形象呢? 举例来说,如果我想前加少许美国国旗图标,或者说“HERP(._。)DERP”,我能做到这一点?

Answer 1:

抱歉,没有。 终端没有做图形。

对于你可以做什么的完整说明,请参见在bash(1)手册页的PROMPTING部分:

PROMPTING

在交互执行时,bash显示主提示PS1,当它准备好读取的命令,并且二次提示PS2时,它需要更多的输入来完成的命令。 bash允许这些提示字符串到通过插入数被解码如下反斜杠转义特殊字符定制:

 \a an ASCII bell character (07) \d the date in "Weekday Month Date" format (eg, "Tue May 26") \D{format} the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required \e an ASCII escape character (033) \h the hostname up to the first '.' \H the hostname \j the number of jobs currently managed by the shell \l the basename of the shell's terminal device name \n newline \r carriage return \s the name of the shell, the basename of $0 (the portion following the final slash) \t the current time in 24-hour HH:MM:SS format \T the current time in 12-hour HH:MM:SS format \@ the current time in 12-hour am/pm format \A the current time in 24-hour HH:MM format \u the username of the current user \v the version of bash (eg, 2.00) \V the release of bash, version + patch level (eg, 2.00.0) \w the current working directory, with $HOME abbreviated with a tilde (uses the value of the PROMPT_DIRTRIM variable) \W the basename of the current working directory, with $HOME abbreviated with a tilde \! the history number of this command \# the command number of this command \$ if the effective UID is 0, a #, otherwise a $ \nnn the character corresponding to the octal number nnn \\ a backslash \[ begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt \] end a sequence of non-printing characters 

命令编号和历史编号通常是不同的:一个命令的历史编号是它在历史列表中,其可以包括从历史文件中恢复的命令位置(见下文历史),而命令数是在序列中的位置当前壳会话期间执行的命令。 字符串被解码之后,将其经由参数扩展,命令替换,算术扩展和引用去除扩大,受promptvars的值shell选项(见禁用了javascript命令的描述下SHELL BUILTIN以下命令)。

\e\[\]转义序列值得特别注意。 有了这些,你可以插入ANSI转义代码命令终端改变前景色,背景色,移动光标,清除屏幕的部分,以及做其他花哨的技巧。

也就是说,例如,你如何迅速改变颜色。 \[\e[0;31m\]设置前景色为红色,和\[\e[0;0m\]重置回默认值。



Answer 2:

事实上,是的,可以。

在最新版本的Bash,至少4(我可以在4.2和4.3做),你可以渲染六角表情符号。

使用echo -e标志。

粘贴你抬头的表情符号中,做一个hexdump都来看看它的材质为:

plasmarob ~ $ echo -n "