Skip to content

ezorita/git-prompt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 

Repository files navigation

A git prompt for bash

With git-prompt you'll hopefully never find yourself again in the following gruesome situations:

  • Resolving merge conflicts manually because you forgot to pull your branch.
  • or even worse, commiting and pushing to the wrong branch 😱

Install

Easy to install, just two simple steps:

Linux

git clone -q https://github.com/ezorita/git-prompt
printf "\nsource $(pwd)/git-prompt/git-prompt" >> ~/.bashrc

MacOS

git clone -q https://github.com/ezorita/git-prompt
printf "\nsource $(pwd)/git-prompt/git-prompt" >> ~/.bash_profile

Features

It's terribly simple:

  • Current branch
  • Sync status
  • Commits ahead/behind remote branch
  • Path relative to repository root

1. Seamless

Automatically turns on when you cd in a git repository.

2. Focus on your repo

Working directory in prompt is relative to your repository root.

3. Autofetch

No need to fetch anymore. It will automatically fetch your current branch every 10 (default) minutes.

4. What's new?

Automatically fetches when you cd to a git repository or change branch.

5. You're out of sync!

Alerts when the last fetch has failed.

6. Easy to turn on and off

Type GIT_PROMPT=0 or gitpr and voilà, you're back to your default prompt.

Here is the alias definition, add it to your bash options file:

alias gitpr='GIT_PROMPT=$((1-{$GIT_PROMPT}))'

7. Easy to customize

Just set the environment variables.

Options

Options can be set directly in the terminal or, if you want to set them permanently, define them anywhere in your .bashrc or .bash_profile file:

Parameter Description
GIT_PROMPT Enables/disables git-prompt (values 1/0) [default 1]
GIT_AUTOFECTH Enables/disables autofecth (values1/0) [default 1]
GIT_AUTOFECTH_INTERVAL Autofetch interval (in seconds) [default 600]
Force_Default_Prompt Overwrite the default prompt as well (values 1/0) [default 0]
GIT_SSH_PRIVATE_KEY Set with path to private key file if different than ~/.ssh/id_rsa, ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, ~/.ssh/id_ecdsa_sk, ~/.ssh/id_ed25519, or ~/.ssh/id_ed25519_sk.

Colors

Colors can be also customized setting the following parameters with \[ ... \]-escaped color sequences:

Parameter Description
User_color Color of the user field [default Bold Green]
At_color Color of the @ symbol [default Purple]
Host_color Color of the host field [default Bold Blue]
Path_color Color of the path field [default Bold Purple]
Branch_color Color of the current branch name [default Green]
Ahead_color Color of the commits ahead indicator [default Green]
Behind_color Color of the commits behind indicator [default Red]
NoSync_color Color of the out-of-sync symbol [default Red]
Fetch_color Color of the fetch... message (do not escape with \[...\]) [default \033[0;32m]
Git_color Color of the git prompt indicator :g~ [default White]
Prompt_color Color of the prompt $ [default White]
Prompt_error_color Color of the prompt $ when the last command failed [default Bold Red]

Compatibility

git v1.9.1

Issues and bugs

Feel free to open a new issue if you find a bug or have feature suggestions.

Thanks!

About

A git prompt for bash

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages