我知道您可以通过编辑~/.bashrc文件中的PS1变量来永久更改bash提示符,我的看起来像这样:
PS1="\[\e[0;31m\]<HERP(._.)DERP>\[\e[0;0m\]";
但是你能否在这里也设置一个小图像呢?例如,如果我想在“HERP(._.)DERP”之前添加一个美国国旗图标或其他图标,我可以这样做吗?
实际上,是的,你可以。
在Bash的最新版本中,至少在4.2和4.3中,你可以使用十六进制渲染表情符号。
使用echo -e
标志。
粘贴一个你查找的表情符号并进行十六进制转储以查看其构成:
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
中。
编辑:由于此帖子中的标志现在呈现为“US”字符,因此可能有一些与SO或浏览器渲染相关的问题。 YMMV,但我认为它仍将在所述版本的bash中工作。
export PS1="\360\237\232\251 > "
可以在你的提示符中显示一个国旗。⚐ → U+2690 ; WHITE FLAG
⚑ → U+2691 ; BLACK FLAG
PROMPTING
When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:
\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
The command number and the history number are usually different: the history number of a command is its position in the history list, which may include commands restored from the history file (see HISTORY below), while the command number is the position in the sequence of commands executed during the current shell session. After the string is decoded, it is expanded via parameter expansion, command substitution, arithmetic expansion, and quote removal, subject to the value of the promptvars shell option (see the description of the shopt command under SHELL BUILTIN COMMANDS below).
\e
、\[
和\]
这三个转义序列非常重要。使用它们,您可以插入ANSI转义代码来控制终端更改前景色、背景色、移动光标、擦除屏幕的部分内容以及进行其他花哨的技巧。\[\e[0;31m\]
将前景色设置为红色,\[\e[0;0m\]
将其重置回默认值。无法向 Bash 提示符添加图标(位图或矢量图形)。
hexdump
可能需要使用-C
选项来考虑大小端。参考链接:https://unix.stackexchange.com/questions/55770/does-hexdump-respect-the-endianness-of-its-system - Nik