Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have found a Tmux configuration file that shows how to add the Git branch to the Tmux status line, however It just shows [[ branch ]] no matter if I am in a Git repo or not. I am not sure if this requires git-completion, but if so I'm not even sure if it is installed as it is a 'virtual' package in Ubuntu (the leading 'v' means 'virtual'):

$ aptitude search git-completion
v   git-completion

$ sudo apt-get install git-completion
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'git' instead of 'git-completion'
git is already the newest version.

How might I add the branch and also the git repo name for the CWD to the Tmux status line?

Thanks.

share|improve this question
up vote 4 down vote accepted

I developed a Bash script for doing that: tmux-git.

tmux-git shows the Git branch of the current working directory, and also checks for uncommited and stashed changes.

share|improve this answer
    
Great, thank you! – dotancohen Oct 7 '13 at 7:22
1  
This doesn't really answer the question, just provides a workaround for bash users. – Hugo Apr 25 at 11:43

For the sake of completeness, I want to mention this other solution I developed in order to show the status of the current Git working tree in tmux: tmux-gitbar.
Although it's not a fork of the excellent tmux-git, it's based off of it.

Here's the screencast on the project pageREADME:

tmux-gitbar screencast

As well as showing the branch and remote, it shows additional information about the status of the Git working tree :

  • number of commits ahead / behind upstream branch, branch divergence
  • number of changed files, staged, modified, conflicts and *stashes** elements
  • colors

How it works

A callback is added to the$PROMPT_COMMANDenvironment variable (its value gets evaluated each time a command is run in the shell).
This callback updates the tmux status bar with the detailed information it parses from git status --porcelain etc....
Or, it does nothing in caseCWDis not a Git working tree, and lets tmux shows anything previsouly declared in thetmux.conffile instead.

share|improve this answer

This is a lot easier in newer versions of tmux:

set -g status-right '#(cd #{pane_current_path}; git rev-parse --abbrev-ref HEAD)'
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .