This tmux plugin sets some tmux environment variables with information about the current git repository.
It is based of tmux-gitbar, but gives the user more freedom to create his own statusbar with the variables.
Install this plugin with tpm.
set -g @plugin '0phoff/gitmux'
In your tmux config, you can use the following variables
- GITMUX_SCRIPT : Path to the update script (This is a global tmux variable, access it with tmux showenv -g)
- GITMUX_REPO : This value is non-zero if the current pane is in a git repository
- GITMUX_BRANCH : Name of the current branch
- GITMUX_REMOTE : Name of the tracking branch (0 if none)
- GITMUX_COMMITS_AHEAD : Number of commits the current branch is ahead of the remote tracking branch
- GITMUX_COMMITS_BEHIND : Number of commits the current branch is behind of the remote tracking branch
- GITMUX_STAGED : Number of files that are staged for the next commit
- GITMUX_CHANGED : Number of files that have changed since last commit (but not staged)
- GITMUX_UNTRACKED : Number of untracked files
- GITMUX_STASHED : Number of stashes
- GITMUX_CONFLICTS : Number of files with conflicts
- GITMUX_CLEAN : This value is 1 when there are no files untracked,changed or staged, no stashes and no conflicts
If you want to update your statusbar whenever you save a file in Vim, add the following line to your vim config:
autocmd BufWritePost * silent! !eval $(tmux display -p "#{GITMUX_SCRIPT}")
Alternative for neovim, that uses the jobcontrol feature to run the command asynchronously (and thus does not block the editor whilst running the command)
autocmd BufWritePost * silent! jobstart(['bash', '-c', 'eval $(tmux display -p "#{GITMUX_SCRIPT}")'])
If you use the PROMPT_COMMAND variable in your terminal configuration, be sure to have it in this format:
PROMPT_COMMAND=" …your_functions_here… ;$PROMPT_COMMAND"
NOTE:
Some distributions like ubuntu, reset the $PROMPT_COMMAND upon loading a terminal, which causes this plugin to fail.
If the plugin does not seem to update when you enter a git repository check the files /etc/bash.bashrc
and /etc/profile
and all the files they source.
Eg. for ubuntu, you need to comment out the following line, at the end of the file /etc/profile.d/vte-2.91.sh
:
[ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command"
Here is an example of how I use this plugin to show information on my status bar.
# Shorted version, only important parts are shown
set -g status-right '#{?GITMUX_REPO,#[fg=red]#{GITMUX_UNTRACKED} #[fg=yellow]#{GITMUX_CHANGED} #[fg=green]●#{GITMUX_STAGED} #[fg=white] #[fg=green]↑#{GITMUX_COMMITS_AHEAD} #[fg=red]↓#{GITMUX_COMMITS_BEHIND} #[fg=white] ⎇ #{GITMUX_BRANCH} , }'
# Actual full version of the statusline I use
set -g status-right '#{?GITMUX_REPO,#[fg=brightblack]#[bg=black]#[fg=white]#[bg=brightblack] #[fg=red]#{GITMUX_UNTRACKED} #[fg=yellow]#{GITMUX_CHANGED} #[fg=green]●#{GITMUX_STAGED} #[fg=white] #[fg=green]↑#{GITMUX_COMMITS_AHEAD} #[fg=red]↓#{GITMUX_COMMITS_BEHIND} #[fg=white] #{?GITMUX_REMOTE,⎇ #{GITMUX_BRANCH},#[fg=red]⎇ #[fg=white]#{GITMUX_BRANCH}} #[fg=black], }#[fg=blue,bg=black]#[fg=black,bg=blue] #U #H '
Please report bugs and file issues with possible improvements.
If you used this plugin, feel free to share the code and a screenshot of it, so I can add it to the README.