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

Git status – show only directory-names

TL;DR: I’m looking for a command for the terminal, that lists all directories from a git status-command.


Details

If I do a git status I get something like this:

Staged changes
  /path/to/file/foo.php
  /path/to/file/bar.php
  /other/path/foo.php
  /other/path/bar.php
  /some/third/path/foo.php
  /some/third/path/bar.php

Untracked files
  .DS_Store
  /new-folder/
  /new-folder-2/
  /new-folder-3/

And I would like it to do output something like this instead:

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

Best case:

Staged changes
  /path/to/file/
  /other/path/
  /some/third/path/

Untracked files
  /
  /new-folder/
  /new-folder-2/
  /new-folder-3/

Next-best thing:

/
/path/to/file/
/other/path/
/some/third/path/
/new-folder/
/new-folder-2/
/new-folder-3/

Idea 1: Grep

I could do something like this:

git status -s | grep -r "Some-badass-regex"

But I’m not strong in regex’es.

>Solution :

You could do it with sed then sort the result, something like this

git status -s | sed "s/\/[^\/]*$/\//" | sort -u

(The regex here is searching for "a slash followed by any number of non-slash characters then end of string" and replacing it with a simple slash.)

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