A moonbase.git prompt
Stefan Wold
ratler at lunar-linux.org
Thu Jan 7 13:40:16 CET 2010
There is a simpler way actually, git module already provide a set of git
bash functions: simply add this to your PS1 and you're set:
\$(__git_ps1 ' (%s)') example: PS1="\u@\h \w \$(__git_ps1 ' (%s)')\\$ "
As soon as you step into a git directory the current branch will popup
as (master) in your prompt. It will also detect som other stuff as on
going merges, bisect etc etc.
--
Sincerely
Stefan Wold
Lunar Linux developer - PGP public key 6E810F05
On Wed, 2010-01-06 at 16:56 -0500, Dennis Veatch wrote:
> Florin made mention today in IRC about a "proper git prompt" and not realizing
> he was in his dev branch. That got me to thinking it would be nice if your
> bash prompt would change to reflect where you were at in your local
> repository. So instead of reinventing the wheel, I looked around and found a
> guy that has what I think a suitable answer;
>
> http://aaroncrane.co.uk/2009/03/git_branch_prompt/
>
> In a nutshell, put this in your .bash_profile;
>
> 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=''
> }
>
> green=$'\e[1;32m'
> magenta=$'\e[1;35m'
> normal_colours=$'\e[m'
>
> PS1="\[$green\]\u@\h:
> \w\[$magenta\]\$git_branch\[$green\]\\$\[$normal_colours\] "
>
> PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
>
>
> It works rather well afaict at this point. The nice thing about this is it
> does not depend on the name of your repository because it looks at the
> contents of .git/HEAD.
>
> Perhaps with a little tweaking from others we might want to add that to our
> bash module.
>
> Dennis
> _______________________________________________
> Lunar-dev mailing list
> Lunar-dev at lunar-linux.org
> http://foo-projects.org/mailman/listinfo/lunar-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part
URL: <http://foo-projects.org/pipermail/lunar-dev/attachments/20100107/f9dbce07/attachment.bin>
More information about the Lunar-dev
mailing list