如何将图标添加到bash提示符

我知道你可以通过编辑〜/ .bashrc文件中的PS1variables来永久编辑bash提示,我的看起来像这样:

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

但是你能在那里设置一个小小的图像吗? 例如,如果我想在“HERP(._。)DERP”之前添加一点美国国旗图标,我可以这样做吗?

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

有关可以执行的操作的完整说明,请参阅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 

命令编号和历史编号通常是不同的:命令的历史编号是其在历史列表中的位置,其可以包括从历史文件恢复的命令(参见下面的历史记录),而命令编号是序列中的位置在当前shell会话中执行的命令。 字符串解码后,通过参数扩展,命令替换,算术扩展和引用移除来扩展,取决于promptvars shell选项的值(请参阅下面的SHELL BUILTIN COMMANDS下的shopt命令的描述)。

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

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

现在,如果你有一个表情符号字体,你可以添加表情符号。 当这个问题最初发布时,我想这不是一个简单可行的选择

几年前我写了这篇博文 。

我不知道美国国旗,但是export PS1="\360\237\232\251 > "在你的提示中得到一个标志。

我也写了一个shell工具,使打印echo或shell提示更容易一些。 这叫做emo

其实,是的,你可以。

在最近版本的Bash中,至少有4个(我可以在4.2和4.3中做到这一点),你可以使用十六进制呈现表情符号。

使用echo -e标志。

粘贴你抬头看的表情符号 ,做一个hexdump来看看它是由什么组成的:

 plasmarob ~ $ echo -n "🇺🇸"| hexdump 0000000 f0 9f 87 ba f0 9f 87 b8 0000008 

然后拿到最上面一行,用\ x转义每个十六进制对:

 plasmarob ~ $ echo -e 'See? \xf0\x9f\x87\xba\xf0\x9f\x87\xb8' See? 🇺🇸 

我其实修改我的是:

plasmarob〜⚡

所以是的,拿出这样的一个,并尝试将其添加到您的.bashrc.bash_profile

越接近你会得到白色和黑色的标志:

 ⚐ → U+2690 ; WHITE FLAG ⚑ → U+2691 ; BLACK FLAG 

以上是Unicode字符。 你也可以找一个带有标志的字体 – 我不知道。

没有办法将图标(位图或矢量图形)添加到bash提示符。