imk*_*dal 7 linux bash shell fedora ps1
我知道你可以通过编辑〜/ .bashrc文件中的PS1变量来永久编辑bash提示,我的看起来像这样:
PS1="\[\e[0;31m\]<HERP(._.)DERP>\[\e[0;0m\]";
Run Code Online (Sandbox Code Playgroud)
但是你能在那里设置一个小小的图像吗?例如,如果我想在"HERP(._.)DERP"之前添加一个小的美国国旗图标,我可以这样做吗?
Pla*_*rob 11
实际上,是的,你可以.
在最近的Bash版本中,至少有4个(我可以在4.2和4.3中完成),你可以使用十六进制渲染表情符号.
使用echo -e标志.
粘贴你查找的表情符号并做一个hexdump来看看它是由什么组成的:
plasmarob ~ $ echo -n ""| hexdump
0000000 f0 9f 87 ba f0 9f 87 b8
0000008
Run Code Online (Sandbox Code Playgroud)
然后取出顶线并用\ x转义每个十六进制对:
plasmarob ~ $ echo -e 'See? \xf0\x9f\x87\xba\xf0\x9f\x87\xb8'
See?
Run Code Online (Sandbox Code Playgroud)
我实际上修改了我的:
plasmarob~⚡
所以,是的,想出一个这样的,并尝试将其添加到您的.bashrc或.bash_profile.
抱歉,没有。终端不做图形。
\n\n有关可以执行的操作的完整说明,请参阅bash(1) 手册页的提示部分:
\n\n\n\n\n提示
\n\n当交互执行时,bash 在准备好读取命令时显示主提示符 PS1,在需要更多输入来完成命令时显示辅助提示符 PS2。Bash 允许通过插入一些反斜杠转义的特殊字符来自定义这些提示字符串,这些字符的解码如下:
\n\nRun Code Online (Sandbox Code Playgroud)\n\n\\a an ASCII bell character (07)\n\\d the date in "Weekday Month Date" format (e.g., "Tue May 26")\n\\D{format}\n the format is passed to strftime(3) and the result is inserted into the\n prompt string; an empty format results in a locale-specific time\n representation. The braces are required\n\\e an ASCII escape character (033)\n\\h the hostname up to the first \xe2\x80\x98.\xe2\x80\x99\n\\H the hostname\n\\j the number of jobs currently managed by the shell\n\\l the basename of the shell\xe2\x80\x99s terminal device name\n\\n newline\n\\r carriage return\n\\s the name of the shell, the basename of $0 (the portion following the final\n slash)\n\\t the current time in 24-hour HH:MM:SS format\n\\T the current time in 12-hour HH:MM:SS format\n\\@ the current time in 12-hour am/pm format\n\\A the current time in 24-hour HH:MM format\n\\u the username of the current user\n\\v the version of bash (e.g., 2.00)\n\\V the release of bash, version + patch level (e.g., 2.00.0)\n\\w the current working directory, with $HOME abbreviated with a tilde (uses the\n value of the PROMPT_DIRTRIM variable)\n\\W the basename of the current working directory, with $HOME abbreviated with a\n tilde\n\\! the history number of this command\n\\# the command number of this command\n\\$ if the effective UID is 0, a #, otherwise a $\n\\nnn the character corresponding to the octal number nnn\n\\\\ a backslash\n\\[ begin a sequence of non-printing characters, which could be used to embed a\n terminal control sequence into the prompt\n\\] end a sequence of non-printing characters\n命令编号和历史编号通常是不同的:命令的历史编号是它在历史列表中的位置,其中可能包括从历史文件恢复的命令(见下面的 HISTORY),而命令编号是在序列中的位置当前 shell 会话期间执行的命令数。字符串解码后,将通过参数扩展、命令替换、算术扩展和引号删除等方式进行扩展,具体取决于 Promptvars shell 选项的值(请参阅下面的 SHELL BUILTIN COMMANDS 下的 shopt 命令的说明)。
\n
、\\e和转义序列值得特别注意\\[。\\]通过这些,您可以插入ANSI 转义码来命令终端更改前景色、背景色、移动光标、擦除屏幕的某些部分以及执行其他花哨的操作。
例如,这就是提示符如何改变颜色。\\[\\e[0;31m\\]将前景色设置为红色,并将\\[\\e[0;0m\\]其重置回默认值。
| 归档时间: |
|
| 查看次数: |
6589 次 |
| 最近记录: |