Author: Santtu Lakkala <firstname.lastname@example.org>
Date: Mon, 7 Mar 2011 09:48:38 +0000
Git branch in prompt
1 file changed, 14 insertions(+), 0 deletions(-)
diff --git a/posts/git-branch-in-prompt.md b/posts/git-branch-in-prompt.md
@@ -0,0 +1,13 @@
+# Git branch in prompt
+ While creating set of [bash_completion rules](https://bugs.freedesktop.org/show_bug.cgi?id=34973) for mc-tool, I read some other rule files to see how things are done. I happened to spot some useful functions from git's completion, mainly __git_ps1, which prints the name of the current branch.
+ Having the name of the current branch can save some mistakes every now and then, and with environment variable GIT_PS1_SHOWDIRTYSTATE you can even make it show if there are non-staged and/or non-committed changes in your tree.
+ This is how I used it:
+`PS1='\u@\h \w$(GIT_PS1_SHOWDIRTYSTATE=1 __git_ps1)\$ '`
+By default the output of __git_ps1 is " (name-of-branch)", or "" if current directory does not belong to a git tree. The format string can be given on command line, like " (%s)".
+ The current version seems to have a small glitch that causes it to print give (unknown) for home directory, if you use git global settings.
+\ No newline at end of file