7

How to add vertical space after each command in bash?

Looking for a wee bit of vertical space, not a full line. 1/4 or 1/3 of the line height should do it.

[edit] The space to add is only after the command+output bundle. The lines between command and associated output still use default spacing. Example: do ls, the output is shown using regular line spacing; only after the output do we get the increased spacing to clearly separate command+output pair from the next command+output.

3
  • 2
    How would you implement it on a text console?
    – choroba
    Commented Apr 21, 2015 at 12:03
  • @choroba: "How would you implement it on a text console?" -- If I knew I wouldn't be asking. :-)
    – Daniel
    Commented Apr 21, 2015 at 12:11
  • xterm escapes: \E#3 thru \E#6 - double/single-height/width line top/bottom modes. And they're not alone.
    – mikeserv
    Commented Apr 22, 2015 at 6:15

3 Answers 3

6

This is more a "terminal application" feature/configuration option than a bash option. Bash is not aware of fonts or spaces, that's something related to the terminal.

For example: Mac Os X's terminal program allows to setup more space between the lines: http://osxdaily.com/2015/01/05/increase-line-spacing-terminal-mac-os-x/

If that's what you're looking for, you should check your terminal program to see if it allows you do configure this.

EDIT: If you only want to add extra space to the prompt after the output of the command itselfs, try this:

export PS1='\n\[\033[01;31m\]\u@\H:\[\033[02;36m\] \w \$\[\033[00m\] '

It adds an entire line (\n) but maybe it's better than nothing.

4
  • Although I also use OS X, I'm more interested in Linux/ubuntu. Also, I'd like to have the increased space only between command+output pairs, not in all lines. I've clarified this last point in the question. (Still useful thank you, will upvote when I get enough rep.)
    – Daniel
    Commented Apr 21, 2015 at 12:18
  • According to askubuntu.com/questions/194264/…, there is a terminal named rxvt that allows to do what you want to do in Linux, with the "-lsp number" parameter.
    – sromero
    Commented Apr 21, 2015 at 12:29
  • If you don't mind adding an entire empty line (\n), test this: export PS1='\n\[\033[01;31m\]\u@\H:\[\033[02;36m\] \w \$\[\033[00m\] '
    – sromero
    Commented Apr 21, 2015 at 12:41
  • 1
    Adding \n to PS1 does add a new line after each command. This is a good answer but I'll still leave the question open in case someone has an idea on how to add partial line height.
    – Daniel
    Commented Apr 21, 2015 at 13:21
3

I'm not aware of any terminal emulator supporting anything along these lines. The very basic concept of a terminal (or graphical terminal emulator) is to work with a text grid. The screen is divided into a matrix of cells of equal size and each cell contains a letter. You can print a simple text flow, but you can also position the cursor arbitrarily within the grid and override the contents of any cell.

There are certain exceptions, e.g. a CJK letter takes up two adjacent cells, and xterm even supports printing a normal letter in double width and/or double height (I've never seen it being used anywhere except for terminal tests), but then it's still aligned to the basic grid.

What you're asking for would require to redesign the whole concept from scratch. Allow arbitrary positioning by some means which don't exist now, and figuring out what should happen if a character is printed somewhere where it partially overlaps a previously printed character.

This would result in a way more complex system than what terminal emulators offer you, for marginal benefit.

What I can recommend to you so that the end of a command's output stands out is to have a prompt with a special color, maybe bold or italic font or something along these lines.

1

Put the following into a file:

command1()
{
    if [ "$BASH_COMMAND" != command2 ]
    then
        command_flag=1
    fi
    return 0
}
trap command1 debug
command2()
{
    if [ "$command_flag" ]
    then
        echo ""
    fi
    command_flag=
}
PROMPT_COMMAND=command2

I advise you to change the names command1, command2, and command_flag to values that you’re not likely to type.  Then source that file.  (Or just put the above into your .bashrc.)

The trap command1 debug command causes the command1 function to be called any time you type a command.  The command1 function sets the command_flag flag to indicate that there was a command.  (The command1 function is not called when you just hit Enter.)

PROMPT_COMMAND=command2 causes the command2 function to be called whenever the shell is about to issue a PS1 prompt.  The command2 function checks the command_flag flag to see whether you typed a command or just Enter.  If you typed a command, command_flag will be set and command2 will write a blank line to the screen.  (If you figure out how to create a vertical space that’s a fraction of a line, change the echo command.)  If you just hit Enter, command_flag will not be set.  Then clear the flag so the next prompt will be done correctly.

Note that the command1 function is called when the shell runs the command2 function; therefore, command1 needs to make it a special case (it doesn’t count as a command).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .