Dan L
Dan L

Reputation: 4439

Indenting terminal/shell output

I've customized the look/feel of my terminal prompt extensively so that it outputs the following (for development work):

== [~/current/path] (git_branch_name) $

I use the == to help identify the prompt lines when I'm looking at a big blog of text.

However, after using this for a few months, I find it's difficult to easily glance at the terminal and know what's what.

I had the idea that indenting all the output would help with that. I know I can change the color as well, but wanted to play with both solutions.

But I have no idea how to indent all output that gets sent to the terminal. MAN pages didn't help me and I couldn't find much on Google.

What I am trying to do

$ some_command_that_outputs_text All lines of output are indented 2 spaces... All lines of output are indented 2 spaces... All lines of output are indented 2 spaces... All lines of output are indented 2 spaces... $ another_terminal_prompt More lines are indented 2 spaces... More lines are indented 2 spaces... More lines are indented 2 spaces... More lines are indented 2 spaces...

Updated: 2014-10-24

Note that I have already customized my color scheme for my terminal as well as the prompt itself. I found that the color scheme wasn't enough for me personally to locate my commands as much of the text itself has similar coloring as my prompt itself.

Upvotes: 4

Views: 6319

Answers (2)

chaos
chaos

Reputation: 9302

In your current bash you can do the following:

exec 1> >(sed -r 's/^(.*)/  \1/g')

Or use that if your sed implementation does not support the -r flag:

exec 1> >(sed 's/^/ /')

That redirects the standard output file descriptor (stdout) to sed, that adds two newline to every line of the outout. Try it with:

$ ls -l
  total 0
  drwxr-xr-x 2 root root 40 Oct 22 16:35 dir
  -rw-r--r-- 1 root root  0 Oct 22 16:59 file
$

Upvotes: 5

R J
R J

Reputation: 1954

You can use tput to move the cursor to an absolute position.

tput cup x y

Where and x and y are the row and column positions before echo the output.

man tput

For details.

Upvotes: -4

Related Questions