简体   繁体   中英

Add newline after output of every bash command

I'm in the process of customizing my terminal.

Currently, I have the following:

前

What I want is a newline after the output of every command, like this:

后

The only way I have been able to accomplish something close to this is by adding a newline at the beginning of my PS1 . This works, but it annoys the hell out of me that the first time I open up a bash prompt, there is a newline above the very first line. Is there any other way to accomplish this?

One approach using printf :

$ printf '%s\n' * $'\n'

or better (for every command):

$ PROMPT_COMMAND="echo"
$ ls

From man bash :

If PROMPT_COMMAND is set and has a non-null value, then the value is executed just as if it had been typed on the command line.

将@GillesQuenot 的回答与@chepner 的评论相结合,这似乎可行,而且非常简单:

PROMPT_COMMAND="export PROMPT_COMMAND=echo"

Adding up @GillesQuenot's answer + @chepner's comment with a neat hack for the clear command:

# Print newline AFTER executing a command
PROMPT_COMMAND="export PROMPT_COMMAND=echo"
alias clear="unset PROMPT_COMMAND; clear; PROMPT_COMMAND='export PROMPT_COMMAND=echo'"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM