8

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

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

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

4

6 回答 6

15

事实上,是的,你可以。

在最近的 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? 

我实际上将我的修改为:

等离子~⚡

所以,是的,想出一个这样的并尝试将它添加到您的.bashrcor.bash_profile中。

编辑:SO 或浏览器渲染的某些内容可能已经改变,因为这篇文章中的标志现在呈现为“美国”字符。YMMV,但我认为它仍然可以在指定的 bash 版本中工作。

于 2016-05-25T20:41:32.783 回答
7

如今,如果您有可识别表情符号的字体,则可以添加表情符号。我想当问题最初发布时,这不是一个容易可行的选择

几年前我写了这篇关于它的博客文章。

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

我还编写了一个 shell 工具,使打印 echo 或 shell prompt 的转义更容易一些。这叫emo

于 2015-05-22T08:56:01.370 回答
3

距离越近,白旗和黑旗就越多:

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

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

于 2012-11-19T19:59:31.513 回答
2

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

有关您可以做什么的完整描述,请参见 bash(1) 手册页的PROMPTING部分:

提示

交互执行时,bash 在准备好读取命令时显示主要提示 PS1,在需要更多输入以完成命令时显示辅助提示 PS2。Bash 允许通过插入一些反斜杠转义的特殊字符来自定义这些提示字符串,这些特殊字符解码如下:

\a     an ASCII bell character (07)
\d     the date in "Weekday Month Date" format (e.g., "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 (e.g., 2.00)
\V     the release of bash, version + patch level (e.g., 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

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

和转义\e序列值得特别注意\[\]使用这些,您可以插入ANSI 转义码来命令终端更改前景色、背景色、移动光标、擦除屏幕的某些部分,以及执行其他花哨的技巧。

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

于 2012-11-19T18:34:07.867 回答
0

如果您希望能够做到这一点,您可以搜索大量不同的图标。

https://emojipedia.org/

我从那个网站得到这个。

于 2019-12-07T03:20:52.277 回答
-2

无法在 bash 提示符中添加图标(位图或矢量图形)。

于 2012-11-19T18:51:28.777 回答