0

Is there a possibility to use e.g sed tool to make git status display only the filename, without any path? Instead of:

/relative/path/to/file/filename.py

I would welcome just:

filename.py

I have very long paths in my project, what makes the output of git status hardly readable.

Example of git status output:

modified:   d/da/mvp/view/dialogelement/composite/Tab.py
modified:   da/dab/core/api/Messages.py
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Krzysztof
  • 129
  • 2
  • 11

2 Answers2

2

With Bash:

for fname in $(git status --short | cut -d ' ' -f 2); do basename $fname; done

Will gives you expected output. But be careful, directories will appears as files.

Arount
  • 9,853
  • 1
  • 30
  • 43
  • It has some disadvantage - when there are sections of Modified and Untracked files, it shows only the lower one, but it's a great help anyway. Thanks – Krzysztof Dec 28 '18 at 14:40
  • @Krzysztof tell me more please, looks like fun to dig in – Arount Dec 28 '18 at 14:41
  • Your command doesn't detect anything above: Untracked files: (use "git add ..." to include in what will be committed) – Krzysztof Dec 28 '18 at 14:42
  • @Krzysztof really? here is my output https://gist.github.com/arount/840115d3deca8048ef57ca693aff919d (`four` is outputed by my command) – Arount Dec 28 '18 at 14:44
1

You could do something like this:

git status | sed 's-\(#\t\+modified: \+\)\(.*/\)\([^/]\+\)-\1.../\3-'

This will replace any text starting with modified: and a bunch of spaces containing slashes with .../ until the last slash. The prefix, spaces and last part of the path will be untouched.

A similar result can be achieved with fewer backslashes using the -E or -r flag:

git status | sed -E 's-(#\t+modified: +)(.*/)([^/]+)-\1.../\3-'
Mad Physicist
  • 107,652
  • 25
  • 181
  • 264