[英]Adding a line break after PS1
I'm trying to add a line break after my prompt. 我正在尝试在提示符后添加换行符。 Basically I want:
基本上我想要:
$ ls
<-- how do I get this line break?
file1 file2 file3
<-- this one is easy, PS1="\n$ " or whatnot
$
instead of 代替
$ ls
file1 file2 file3
$
If you are using Bash, you can use a script like this one to provide preexec
functionality. 如果您使用的是Bash,则可以使用像这样的脚本来提供
preexec
功能。
Using preexec
, you can add the newline after the prompt by editing your .bash_profile
to include 使用
preexec
,您可以通过编辑.bash_profile
来在提示后添加换行符,以包括
preexec() { echo; }
preexec_install
Note that I had to modify line 125 of the above-linked script to read 请注意,我必须修改上面链接的脚本的第125行以读取
PROMPT_COMMAND="${PROMPT_COMMAND} preexec_invoke_cmd"
on my OS X box. 在我的OS X盒子上。
If you just want this functionality on a case by case basis, you could do this: 如果只是根据情况需要此功能,则可以执行以下操作:
$ echo -e "\n" && ls
(ie tell echo to insert a newline, then run your regular command. The -e flag tells echo to interpret escape sequences. Not all system configurations need it) (即告诉echo插入换行符,然后运行常规命令。-e标志告诉echo解释转义序列。并非所有系统配置都需要它)
For brevity you can create an alias, and use it whenever you want some whitespace 为简便起见,您可以创建一个别名,并在需要空白时使用它
$ alias ws='echo -e "\n"'
$ ws && echo "I am padded text"
I am padded text
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.