11

I'm in the process of customizing my terminal.

Currently, I have the following:

before

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

after

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?

KyleMit
  • 45,382
  • 53
  • 367
  • 544
bitpshr
  • 1,003
  • 1
  • 9
  • 20
  • `there is a newline above the very first line` Is that such a big problem? – anubhava Oct 26 '13 at 17:39
  • 2
    Not really, just curious if there is a better way. It rubs my OCD the wrong way :( – bitpshr Oct 26 '13 at 17:41
  • 1
    Actually putting a newline above the very first line probably *is* the best way – super cheap and easy to understand. – kojiro Oct 26 '13 at 18:08
  • @bitpshr Can I see your bashrc that gets you that format? I'd like to use it (I don't mind the newline when I first open the terminal) – RTF Jul 17 '20 at 09:07

2 Answers2

12

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.

KyleMit
  • 45,382
  • 53
  • 367
  • 544
Gilles Quenot
  • 143,367
  • 32
  • 199
  • 195
  • 1
    I like this method, but this is interpreted before `PS1` and still prints a newline above the very first line of the bash prompt, essentially equivalent to a newline at the beginning of `PS1`. I may be doing something wrong... – bitpshr Oct 26 '13 at 17:48
  • 1
    I'm really not sure how this is different from putting a newline at the beginning of PS1, which what OP asked not to do. (Except PROMPT_COMMAND is slightly more expensive.) – kojiro Oct 26 '13 at 18:08
  • 1
    I once [posted an answer](http://stackoverflow.com/a/14860632/1126841) showing how to define `PRMOPT_COMMAND` in such a way that it redefines itself the first time it is called. You could adapt that so that `echo` is *not* called the very first time it is used in the shell, but is for each subsequent use. – chepner Oct 26 '13 at 19:27
  • Is there a way to get this to work after every line of *output* instead of every command? – Cole May 20 '20 at 07:42
  • `PROMPT_COMMAND="export PROMPT_COMMAND=echo"` seems to work – qwazix Feb 12 '21 at 15:19
2

Combining @GillesQuenot's answer with @chepner's comment this seems to work and it's quite simple:

PROMPT_COMMAND="export PROMPT_COMMAND=echo"
qwazix
  • 686
  • 8
  • 14