/dev/blah

things i want to remember, things i want to share

Développeur Python et adepte Linux depuis 2005, passionné par beaucoup trop de choses. Profil Github

Entries tagged “workflow.”

Monitoring your git status.

written by tshirtman, on 2/20/14 1:58 AM.

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.

The watch linux command allow to execute a command every nth second (n being 2 by default), so you can let that run in a shell next to the one you work in.

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 -t option:

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 .gitignore, 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 ;).

Tip me if you like this :)

Tags

#FIXME 3G absurd ad_sense alterway aléatoire android animation anonymity atheism bach backlog bash bitcoins blog blogging boldness book books boulot bricolage bépo C canvas captcha captures carte SD censure christianity chroot CLI cli cloudwatt code colors comfort zone command line community company life conferences contest copwatch copwatchnord-idf core-devs cours ct705 culture deb debian debug deformation dehors dessin dev distribute distribution débutant déploiement développement ebooks eeepad eeepc effect ego empty en escher event firefly flappy bird flask fosdem foss fr fun game garden gdb geek culture git github goals graphics grrr gödel hack hackathon hacked hacking hooks i3 images IMAP inspirational install isync java jeu jeu video jinja2 jni keyboard keynav kivy kv lame learning lib libre life linux lol macosx magnet mail mailing-list mails maths mbsync meetings memory leak mesh meta mint mirroir MIT module motivational mouse museomix mutt nexus7 no-mouse notmuch nottoomuch offlineimap onycroit opencourseware osc packaging paris passphrase password patch pentacatyl people perte de données ping pip planning plugin positioning pr procrastination programmation progress project projet property proudhon proxy psf publisher/consumer pull-down pygame pyjnius pypi python pythonar qtile raid rapsberry pi reading recorder references release religion responsive review reviews réseau réseaux sociaux résurection salon screenshots script self service shows shutil shyness sizing solib sortie sousous!!! spam spritz stash status systeme système templating terminal texture texture coordinates Thomas Paine thread thème tiling time time management. tip tips tools transformer tutorial tv twitter typematrix typing ubuntu ubuntu-fr ultimate-smash-friends unity upload images useless usf utils value VDM video vie/mort vim virtualenv visite widget windows wm wmii work workflow workflow. zine études