4.0 KiB
Git Aware Prompt
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's 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.
Installation
Clone the project to a .bash folder in your home directory:
mkdir ~/.bash
cd ~/.bash
git clone git://github.com/jimeh/git-aware-prompt.git
Edit your ~/.bash_profile or ~/.profile and add the following to the top:
export GITAWAREPROMPT=~/.bash/git-aware-prompt
source $GITAWAREPROMPT/main.sh
Configuring
Once installed, there will be new $git_branch and $git_dirty variables
available to use in the PS1 environment variable, along with a number of
color helper variables which you can see a list of in colors.sh.
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.
Mac OS X
export PS1="\u@\h \w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
Optionally, if you want a nice pretty prompt when using sudo -s, also add
this line:
export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "
Ubuntu
Standard:
export PS1="\${debian_chroot:+(\$debian_chroot)}\u@\h:\w \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
Colorized:
export PS1="\${debian_chroot:+(\$debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] \[$txtcyn\]\$git_branch\[$txtred\]\$git_dirty\[$txtrst\]\$ "
Updating
Assuming you followed the default installation instructions and cloned this
repo to ~/.bash/git-aware-prompt:
cd ~/.bash/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
(MIT-like license, without the requirement to keep copyright notice or license in reproductions)
Copyright (c) 2015 Jim Myhrberg
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
