Is there either an existing command, or some trick or script that allows me to show the status of the files shown in "ls"?
Something like the following:
$ git ls status #Command could be anything `lsg` is fine too, whatever. app contents modified autotest up-to-date config up-to-date config.ru staged db contents modified doc contents modified Gemfile modified Gemfile.lock modified lib up-to-date log up-to-date public up-to-date Rakefile up-to-date README up-to-date script up-to-date spec up-to-date tmp up-to-date vendor contents modidified test.tmp removed
In any way: having the git status information available in a directory listing.
git directory with the command ls -a . The ls command lists the current directory contents and by default will not show hidden files. If you pass it the -a flag, it will display hidden files. You can navigate into the . git directory like any other normal directory.
The git status command displays the state of the working directory and the staging area. It lets you see which changes have been staged, which haven't, and which files aren't being tracked by Git. Status output does not show you any information regarding the committed project history.
The Bash command ls is used to 'list' contents of the current working directory. ls is equivalent to DIR on a Windows console host terminal. Both Bash and Windows console host have a cd command. cd is an acronym for 'Change Directory'.
Using the Git status short format information, here's a Bash script that uses Awk and the column
command to give you customized status output.
#!/bin/bash git status --porcelain | \ awk 'BEGIN {FS=" "} { xstat = substr($0, 1, 1); ystat = substr($0, 2, 1); f = substr($0, 4); ri = index(f, " -> "); if (ri > 0) f = substr(f, 1, ri); if (xstat == " " && ystat ~ "M|D") stat = "not updated"; else if (xstat == "M" && ystat ~ " |M|D") stat = "updated in index"; else if (xstat == "A" && ystat ~ " |M|D") stat = "added to index"; else if (xstat == "D" && ystat ~ " |M") stat = "deleted from index"; else if (xstat == "R" && ystat ~ " |M|D") stat = "renamed in index"; else if (xstat == "C" && ystat ~ " |M|D") stat = "copied in index"; else if (xstat ~ "M|A|R|C" && ystat == " ") stat = "index and work tree matches"; else if (xstat ~ " |M|A|R|C" && ystat == "M") stat = "work tree changed since index"; else if (xstat ~ " |M|A|R|C" && ystat == "D") stat = "deleted in work tree"; else if (xstat == "D" && ystat == "D") stat = "unmerged, both deleted"; else if (xstat == "A" && ystat == "U") stat = "unmerged, added by us"; else if (xstat == "U" && ystat == "D") stat = "unmerged, deleted by them"; else if (xstat == "U" && ystat == "A") stat = "unmerged, added by them"; else if (xstat == "D" && ystat == "U") stat = "unmerged, deleted by us"; else if (xstat == "A" && ystat == "A") stat = "unmerged, both added"; else if (xstat == "U" && ystat == "U") stat = "unmerged, both modified"; else if (xstat == "?" && ystat == "?") stat = "untracked"; else if (xstat == "!" && ystat == "!") stat = "ignored"; else stat = "unknown status"; print f " " stat; }' | \ column -t -s " "
If you create an executable git-status-ls
in a directory on your PATH
($HOME/bin
should be a good place), you can type git status-ls
in any Git repo. Or you could create a Git alias one-liner for this. You could also implement this using Perl, Python, C or whatever language you're most comfortable with.
Here's a sample output:
B renamed in index A untracked dont_delete_git_pre-commit_hook untracked
Just realized, tabs are displaying as spaces. In the Awk script print f " " stat;
and in the column -t -s " "
command, there is a tab (not spaces) between the double-quotes. You could use a separator other than tab.
Noticed an issue with the status flags handling in the above script and corrected it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With