It’s not uncommon to query various git commands to know your current state in your repository, before doing the commands that do actual things.
To avoid doing some of them needlessly, or missing important information, it’s a common solution to customize a shell prompt to add the most important information in it.
However, that’s usually quite limited, and when developing on a project, or doing some refactoring or even rebasing, you’ll often do the same commands over and over.
Doing something over and over is bad, it makes you tired and mistake prone, and computers are good at doing repeated actions for you, so you just know to know the right tools.
watch linux command allow to execute a command every
nth second (
being 2 by default), so you can let that run in a shell next to the one you
A first step then is:
watch git status --short
not very advanced, but actually helpful, however, there is a few over commands you’ll want to see, for example, the existing branches and the one you are on, the git log is cool too, and git reflog, being one of my favorites.
watch "git status --short && git branch && git log --graph --oneline && git reflog"
It’s nice to see on what commit a branch is, too, so let’s add that to the branch command.
watch "git status --short && git branch -v&& git log --graph --oneline && git reflog"
We have a problem, though, log and reflog will usually be way longer than our terminal can afford, and you’ll not see reflog at all.
watch "git status --short && git branch -v&& git log --graph --oneline | head -n 10 && git reflog"
(it’s actually not needed to cut the tail of reflog, as it’s the last command)
But all of this is a bit lacking in colors, lets add them!
watch can allow colors to be used, but we still have to force git to show
them. To avoid things getting to messy, we’ll define a few git aliases:
git config --global alias.cstatus "-c color.status=always status --short" git config --global alias.bc "branch --color -v" git config --global alias.ll "log --graph --pretty=format:"%C(yellow)%h %C(blue)%ci%C(green) %an %C(red)%d %Creset%s"
then our watch command can be
watch -c "git cstatus && git bc && git ll | head -n 10 && git reflog --color"
This is starting to look good, but there is some need of a separation between the various commands, i found it best to simply leave an empty line.
watch -c "git cstatus && echo &&git bc &&echo && git ll | head -n 10 &&echo && git reflog --color"
There is still one ugly detail though, and that’s the header produced by the
watch command, thanksfully, it can be easily discarded using the
watch -ct "git cstatus && echo &&git bc &&echo && git ll | head -n 10 &&echo && git reflog --color"
The result is probably that you want to add a few things to
delete a few branches hanging around for no reasons, and slap people doing too
long commit titles :P. Which is probably a good task for the forthcoming spring
Bonus points if you use a tiling windows manager, and can give this a chunk of the side of your screen ;).