【发布时间】:2012-10-23 18:28:07
【问题描述】:
我正在尝试在提示后添加换行符。基本上我想要:
$ ls
<-- how do I get this line break?
file1 file2 file3
<-- this one is easy, PS1="\n$ " or whatnot
$
而不是
$ ls
file1 file2 file3
$
【问题讨论】:
我正在尝试在提示后添加换行符。基本上我想要:
$ ls
<-- how do I get this line break?
file1 file2 file3
<-- this one is easy, PS1="\n$ " or whatnot
$
而不是
$ ls
file1 file2 file3
$
【问题讨论】:
如果您使用的是 Bash,则可以使用 this one 之类的脚本来提供 preexec 功能。
使用preexec,您可以在提示后添加换行符,方法是编辑您的.bash_profile 以包含
preexec() { echo; }
preexec_install
请注意,我必须修改上述链接脚本的第 125 行才能阅读
PROMPT_COMMAND="${PROMPT_COMMAND} preexec_invoke_cmd"
在我的 OS X 机器上。
【讨论】:
tcsh 也有,如postcmd。
如果您只是根据具体情况需要此功能,您可以这样做:
$ echo -e "\n" && ls
(即告诉 echo 插入换行符,然后运行常规命令。-e 标志告诉 echo 解释转义序列。并非所有系统配置都需要它)
为简洁起见,您可以创建一个别名,并在需要一些空格时使用它
$ alias ws='echo -e "\n"'
$ ws && echo "I am padded text"
I am padded text
【讨论】:
'echo -en "\n" && ' 创建一个别名,然后调用类似pad echo "I am padded" 的名称。