user578895
user578895

Reputation:

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
$

Upvotes: 3

Views: 1657

Answers (2)

nneonneo
nneonneo

Reputation: 179392

If you are using Bash, you can use a script like this one to provide preexec functionality.

Using preexec, you can add the newline after the prompt by editing your .bash_profile to include

preexec() { echo; }
preexec_install

Note that I had to modify line 125 of the above-linked script to read

PROMPT_COMMAND="${PROMPT_COMMAND} preexec_invoke_cmd"

on my OS X box.

Upvotes: 2

Ari
Ari

Reputation: 1092

If you just want this functionality on a case by case basis, you could do this:

$ echo -e "\n" && ls

(i.e. 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)

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

Upvotes: 2

Related Questions