Home > Blockchain >  Git status - show only directory-names
Git status - show only directory-names

Time:02-11

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:

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.

CodePudding user response:

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.)

  • Related