• Category Archives git
  • Bash completion and git prompt

    Recently I discovered that the virtual server I was working on did not give me the usual bash completion I’m so used to on my Kubuntu workstations. Working on git repositories and upgrading web applications made this to an itch I just had to scratch.

    After a bit of searching it appeared that I was missing a file: /etc/bash_completion. Next I discovered that there is a /etc/bash_completion.d/ directory and under this a file named ‘git’. I copied the bash_completion file from my workstation and followed the instruction in /etc/bash_completion.d/git and suddenly I had bash completion and a prompt that gave me branch name and the status of the git repository I was currently in.

    Just to give you a hint, here is the comment from the /etc/bash_completion.d/git file:


  • Prompt with git branch

    I think I like this:

    [cc lang=”bash”]
    function parse_git_dirty {
    [[ $(git status 2> /dev/null | tail -n1) != “nothing to commit (working directory clean)” ]] && echo “*”
    function parse_git_branch {
    git branch –no-color 2> /dev/null | sed -e ‘/^[^*]/d’ -e “s/* \(.*\)/[\1$(parse_git_dirty)]/”

    export PS1=’${debian_chroot:+($debian_chroot)}\[\033[01;33m\]\w\[\033[01;32m\] $(parse_git_branch) \[\033[01;36m\]$ \[\033[00m\]’