Recent Posts

Lambdalog

Sean Seefried's programming blog

21 May 2011

Context sensitive aliases for git

As developers many of us use git. Recently Peteris Krumins wrote a post about git aliases. The basic idea was to make aliases such as

for common git commands. However, we can already see a problem. The command for GhostScript is gs. What we really need is context sensitive aliases so that the command gs means git status when one is inside a git repository and gs everywhere else in the directory hierarchy. I whipped up a nice little bash script to generate context sensitive aliases.

By checking the return status of git status one can decide whether to call one command or another. You can then define the aliases in a .bashrc (or similar) configuration file.

The idea of context sensitive aliases is by no means limited to git. It could be used anywhere where you have a way of detecting whether a property (e.g. whether you’re in a repository or not) holds within a directory hierarchy.

Tagged as: git.

blog comments powered by Disqus