git repository information in tmux environment variables
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
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.