Dynamically loading git bash-completion

I have to admit, I love git. It has really made me more efficient, and I can’t honestly think of ever switching back to ie. svn.

My shell is bash, and up until now I used a very simple bash completion for git, but at times I do see myself wanting something a bit more comprehensive. However, I really don’t want bash to be slow to open (of course, the definition of “slow” is quite individual – over a second is way too much ;), which it can be if it needs to load all bash completion definitions when starting. Therefore I wrote a small bash function for my .bashrc that will dynamically load the git bash completion when it first is accessed. Bash starts fast, and I get git bash completion – problem solved (well, the first time git bash completion is used, it of course takes a tad longer than normal because it needs to load it first, but that’s completely livable). As a bonus, it will fall back to my old and simple completion if the proper one is not available.

Here’s the code snippet:

Tags: , ,

3 Responses to “Dynamically loading git bash-completion”

  1. Just a by the way ZSH does that builtins (autoload on demand) and have a fairly complete git completion….. but well a shell can be a hard thing to change….

    • Zero_Dogg says:

      Really? That’s quite neat – I must admit I have very rarely used a shell other than bash.

      Though, like you said, a shell can be a hard thing to change, I’m not sure if I could make myself do it, plus:
      [0 zerodogg@firefly ~]$ wc -l .bashrc
      506 .bashrc

Leave a Reply