initial commit

This commit is contained in:
2009-11-14 00:21:28 +02:00
commit e13bbc4407
4 changed files with 123 additions and 0 deletions

65
README.md Normal file
View File

@@ -0,0 +1,65 @@
# Git Branch in Prompt
Working with Git and it's 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][1] [of][3] [articles][3] [available][4] online about how to achieve this.
I based this project mainly on [Aaron Crane's solution][1].
[1]: http://aaroncrane.co.uk/2009/03/git_branch_prompt/
[2]: http://railstips.org/2009/2/2/bedazzle-your-bash-prompt-with-git-info
[3]: http://techblog.floorplanner.com/2008/12/14/working-with-git-branches/
[4]: http://www.intridea.com/2009/2/2/git-status-in-your-prompt
## Installation
Clone the project to a `.bash` folder in your home directory:
git clone git://github.com/jimeh/git-branch-in-prompt.git ~/.bash
Edit your `~/.bash_profile` or `~/.profile` and add the following to the top:
export DOTBASH=~/.bash
source $DOTBASH/main.sh
PS1="\u@\h:\w\[$txtcyn\]\$git_branch\[$txtrst\]\\$ "
Configure your prompt by editing the `PS1 variable`. For a list of available colors check `colors.sh`.
## Screenshot
![Git Branch in Prompt](http://snap.jimeh.me/git-branch-in-prompt.png)
## Issues
Please report any issues and bugs [here][1] on GitHub.
[1]: http://github.com/jimeh/git-branch-in-prompt/issues
## License
(The MIT License)
Copyright (c) 2009 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, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
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.

33
colors.sh Normal file
View File

@@ -0,0 +1,33 @@
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
bldblk='\e[1;30m' # Black - Bold
bldred='\e[1;31m' # Red
bldgrn='\e[1;32m' # Green
bldylw='\e[1;33m' # Yellow
bldblu='\e[1;34m' # Blue
bldpur='\e[1;35m' # Purple
bldcyn='\e[1;36m' # Cyan
bldwht='\e[1;37m' # White
unkblk='\e[4;30m' # Black - Underline
undred='\e[4;31m' # Red
undgrn='\e[4;32m' # Green
undylw='\e[4;33m' # Yellow
undblu='\e[4;34m' # Blue
undpur='\e[4;35m' # Purple
undcyn='\e[4;36m' # Cyan
undwht='\e[4;37m' # White
bakblk='\e[40m' # Black - Background
bakred='\e[41m' # Red
badgrn='\e[42m' # Green
bakylw='\e[43m' # Yellow
bakblu='\e[44m' # Blue
bakpur='\e[45m' # Purple
bakcyn='\e[46m' # Cyan
bakwht='\e[47m' # White
txtrst='\e[0m' # Text Reset

2
main.sh Normal file
View File

@@ -0,0 +1,2 @@
source $DOTBASH/colors.sh
source $DOTBASH/prompt.sh

23
prompt.sh Normal file
View File

@@ -0,0 +1,23 @@
function find_git_branch {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head == ref:\ refs/heads/* ]]; then
git_branch=" (${head#*/*/})"
elif [[ $head != '' ]]; then
git_branch=' (detached)'
else
git_branch=' (unknown)'
fi
return
fi
dir="../$dir"
done
git_branch=''
}
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
# Default Git enabled prompt
# PS1="\u@\h:\w\[$txtcyn\]\$git_branch\[$txtrst\]\\$ "