Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to indent output of git-clone

I’ve been trying to indent the output of git clone. I tried using sed but it isn’t working… here’s what I’ve tried so far.

git clone https://github.com/test/HelloWorld --progress | sed 's/^/  /g'

Does anyone have any ideas?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Git outputs to both stdout and stderr. To filter both you can use |& or 2&1 |.

It also prints progress lines that are updated in place with \r carriage returns. You could use a regex to also indent those lines in addition to the normal ones. I would also use -u for unbuffered input and output.

git clone https://github.com/test/HelloWorld --progress |&
    sed -ur 's/(^|\r)/\1  /g'

Note that sed is line-based and only prints output when it hits a \n newline. Lines separated with \r carriage returns could be buffered up for a while before being printed.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading