Skip to content

Display the current git branch and summarised git stats in your bash or zsh prompt +*?<>

License

Notifications You must be signed in to change notification settings

tony-sol/git-aware-prompt

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Git Aware Prompt (tony-sol's fork)

Working with Git and its great branching/merging features is amazing. Constantly switching branches can be confusing though as you have to run git status to see which branch you're currently on.

The solution to this is to have your terminal prompt display the current branch. There are a number of articles available online about how to achieve this. This project is an attempt to make an easy to install/configure solution.

Overview

If you cd to a Git working directory, you will see the current Git branch name displayed in your terminal prompt. When you're not in a Git working directory, your prompt works like normal.

This fork by tony-sol also:

  • shows how many stashes you have on stash (when the top stash entry was made on the current commit or the current branch).
  • provided colors.sh won't be loaded for zsh due to performance issue, use autoload -U colors && colors and example bellow instead.

Git Branch in Prompt

≡2 indicates that there are 2 entries on the stash, and last one related to current branch or commit.

≋3 indicates that there are 3 entries on the stash.

<3 indicates that the local branch is 3 commits behind the upstream (remote) branch, and could/should be pulled.

?1 indicates that there is 1 untracked file in the tree.

+1 indicates that one file is staged for comitting.

>1 indicates that the local branch has 1 commit which has not yet been pushed to the upstream.

*1 indicates that the branch is dirty, with 1 file modified but not committed.

# would indicate that git status has taken too long, so the markers are not shown.

In that situation, git status will continue running in the background, so after a few moments, hitting <Enter> again should give you an up-to-date summary.

We also have some indicators for the current branch:

[branch_name] means you are on a branch with an upstream

(branch_name) means you are on a branch without an upstream

{branch_name\mode} means you are in the middle of a merge, rebase, cherry-pick, revert or bisect

<commit_id> means you are detached on the given commit, tag, or remote branch

The symbols (or "markers") can be changed by editing the prompt.sh file directly (and reloading it of course). The numbers or the markers can be omitted by removing the _count or _mark variables from the PS1 prompt below.

See Also

Installation

Clone the project to a shell configuration folder in your home directory, e.g.:

cd "${ZDOTDIR}/extensions/"
git clone git://github.com/tony-sol/git-aware-prompt.git

Edit your shell rc file (e.g. ~/.bash_profile, ~/.profile, ~/.bashrc, ~/.zshrc, ~/.zprofile, etc.) and add the following to the top:

source "${ZDOTDIR}/extensions/git-aware-prompt/main.sh"

Configuring

Once installed, there will be several new variables available to use in the PS1(or PROMPT, RPROMPT) environment variable:

  • $git_ahead_count
  • $git_ahead_mark
  • $git_behind_count
  • $git_behind_mark
  • $git_branch
  • $git_dirty_mark
  • $git_dirty_count
  • $git_staged_count
  • $git_staged_mark
  • $git_stash_count
  • $git_stash_mark
  • $git_unknown_count
  • $git_unknown_mark

If you want to know more about how to customize your prompt, I recommend this article: How to: Change / Setup bash custom prompt (PS1)

Suggested Prompts

Below are a few suggested prompt configurations. Simply paste the code at the end of the same file you pasted the installation code into earlier.

macOS (zsh)

export RPROMPT='%{$fg_bold[green]%}$git_ahead_mark$git_ahead_count%{$fg_bold[red]%}$git_behind_mark$git_behind_count%{$fg_bold[cyan]%}$git_stash_mark$git_stash_count%{$fg_bold[yellow]%}$git_dirty_mark$git_dirty_count%{$fg_bold[blue]%}$git_staged_mark$git_staged_count%{$fg_bold[magenta]%}$git_unknown_mark$git_unknown_count%{$reset_color%}%{$fg[cyan]%}$git_branch%{$reset_color%}'

Ubuntu (bash)

export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w\[$txtcyn\]\$git_branch\[$bldgrn\]\$git_ahead_mark\$git_ahead_count\[$txtrst\]\[$bldred\]\$git_behind_mark\$git_behind_count\[$txtrst\]\[$bldyellow\]\$git_stash_mark\$git_stash_count\[$txtrst\]\[$txtylw\]\$git_dirty_mark\$git_dirty_count\[$txtrst\]\[$txtcyn\]\$git_staged_mark\$git_staged_count\[$txtrst\]\[$txtblu\]\$git_unknown_mark\$git_unknown_count\[$txtrst\]\$ "

Updating

Assuming you followed the default installation instructions and cloned this repo to "${ZDOTDIR}/extensions/git-aware-prompt":

cd "${ZDOTDIR}/extensions/git-aware-prompt"
git pull

Usage Tips

To view other user's tips, please check the Usage Tips wiki page. Or if you have tips of your own, feel free to add them :)

License

CC0 1.0 Universal

About

Display the current git branch and summarised git stats in your bash or zsh prompt +*?<>

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Languages

  • Shell 100.0%