Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Adding Git repo and branch to Tmux status line

Writer Sophia Terry

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.

3 Answers

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.

1

This is a lot easier in newer versions of tmux:

set -g status-right '#(cd #{pane_current_path}; git rev-parse --abbrev-ref HEAD)'
1

I developer a platform and shell-independent solution to show Git working tree information into Git status bar: gitmux.
Here's the screencast on the project pageREADME:

gitmux 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

By adding set -g status-right '#(gitmux #{pane_current_path})' to your .tmux.conf, gitmux gets called each the working directory updates or a command is entered in a terminal, gitmux prints a tmux format string of git status, that gets shown in tmux status bar. Or, nothing gets printed in case the working directory is not managed by Git.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy