{"thread":{"id":"43077","subject":"Re: git-PS1 bash prompt setting","startedAt":"2006-11-16T18:01:11Z","lastAt":"2006-11-27T17:38:30Z","messageCount":13,"participants":["Junio C Hamano","Shawn Pearce","Sean","Johannes Schindelin","Nicolas Vilz","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"294393","messageId":"BAYC1-PASMTP037FDA6C6465F0541AC613AEE90@CEZ.ICE","threadId":"43077","inReplyTo":null,"subject":"git-PS1 bash prompt setting","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2006-11-16T18:01:11Z","receivedAt":"2006-11-16T18:01:11Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"\nTed mentioned in the wart thread that having multiple branches per repo\nmeans that the standard bash prompt isn't as much help as it could be.\n\nFor what it's worth i'll post a little script i've been using for quite\nsome time that helps a little.  It's called git-PS1 and is used by\nincluding it in your bash PS1 variable like so:\n\nexport PS1='$(git-PS1 \"[\\u@\\h \\W]\\$ \")'\n\nIf you're not in a git repo, the bash prompt you pass on the git-PS1\ncommand line is used instead.  If you are in a git repo, you'll get\nthe following as a prompt:\n\n[branch!repo/relative/path]$ \n\nWhere \"repo\" is the basename of the path to the root of your repo.\nAn example would look like this:\n\n[master!linus-2.6/Documentation/vm]$ \n\nCheers,\nSean\n\n\n#!/bin/bash\nBR=$(git symbolic-ref HEAD 2>/dev/null) || { echo \"$@\" ; exit ; }\nBR=${BR#refs/heads/}\nREL=$(git rev-parse --show-prefix) \nREL=\"${REL//%\\/}\"\nLOC=\"${PWD%/$REL}\"\necho \"[$BR!${LOC/*\\/}${REL:+/$REL}]$ \"\n"},{"id":"293816","messageId":"7vd57n9r3t.fsf@assigned-by-dhcp.cox.net","threadId":"43077","inReplyTo":"BAYC1-PASMTP037FDA6C6465F0541AC613AEE90@CEZ.ICE","subject":"Re: git-PS1 bash prompt setting","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-16T18:35:50Z","receivedAt":"2006-11-16T18:35:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sean <seanlkml@sympatico.ca> writes:\n\n> Ted mentioned in the wart thread that having multiple branches per repo\n> means that the standard bash prompt isn't as much help as it could be.\n\nYes, I think this is common issue for everybody not just people\nwho worked with BK or mercurial.  I find myself almost typing\n\"pwd\" to find out what branch I am on (I do not go as far as\ntyping \"git cd\" to switch branches, though).\n"},{"id":"294700","messageId":"Pine.LNX.4.63.0611261524130.30004@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43077","inReplyTo":"BAYC1-PASMTP037FDA6C6465F0541AC613AEE90@CEZ.ICE","subject":"Re: git-PS1 bash prompt setting","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-11-26T14:27:07Z","receivedAt":"2006-11-26T14:27:07Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Thu, 16 Nov 2006, Sean wrote:\n\n> For what it's worth i'll post a little script i've been using for quite\n> some time that helps a little.  It's called git-PS1 and is used by\n> including it in your bash PS1 variable like so:\n> \n> export PS1='$(git-PS1 \"[\\u@\\h \\W]\\$ \")'\n\nI actually like that very much! So much that I tried to implement this as \nan option to an existing builtin (I did not want to clutter the list of \ncommands any more...).\n\nBut there really is no good place to put it: most commands need a git \nrepository, and those which do not, are inappropriate to put an option \n\"--show-ps1\" into. Except maybe repo-config. Thoughts?\n\nCiao,\nDscho\n"},{"id":"296059","messageId":"BAYC1-PASMTP0478559E108A91E0F2A038AEE70@CEZ.ICE","threadId":"43077","inReplyTo":"Pine.LNX.4.63.0611261524130.30004@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: git-PS1 bash prompt setting","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2006-11-26T14:42:12Z","receivedAt":"2006-11-26T14:42:12Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Sun, 26 Nov 2006 15:27:07 +0100 (CET)\nJohannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n\n> But there really is no good place to put it: most commands need a git \n> repository, and those which do not, are inappropriate to put an option \n> \"--show-ps1\" into. Except maybe repo-config. Thoughts?\n\nWhat about just making it an option to the git wrapper?\n\n"},{"id":"296144","messageId":"20061126150523.GB18828@hermes.lan.home.vilz.de","threadId":"43077","inReplyTo":"20061126094212.fde8cce7.seanlkml@sympatico.ca","subject":"Re: git-PS1 bash prompt setting","fromName":"Nicolas Vilz","fromEmail":"niv@iaglans.de","sentAt":"2006-11-26T15:05:23Z","receivedAt":"2006-11-26T15:05:23Z","isPatch":false,"sender":{"key":"niv@iaglans.de","avatar":"https://gravatar.com/avatar/e4d43a32d721241212d4edb1d2210327e28423c913071b4bfeeaa0ce15296110?d=mp&s=160"},"body":"On Sun, Nov 26, 2006 at 09:42:12AM -0500, Sean wrote:\n> On Sun, 26 Nov 2006 15:27:07 +0100 (CET)\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> \n> > But there really is no good place to put it: most commands need a git \n> > repository, and those which do not, are inappropriate to put an option \n> > \"--show-ps1\" into. Except maybe repo-config. Thoughts?\n> \n> What about just making it an option to the git wrapper?\n\nI glued that in my system bashrc with the extension, that it shows to me\nuser.email out of repo-config, which is also very handy. So I am always\nreminded to set my user.credentials in .git/config and i always know which \nrole i play in the repository i am working at.\n\n"},{"id":"297877","messageId":"Pine.LNX.4.63.0611261617470.30004@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"43077","inReplyTo":"BAYC1-PASMTP0478559E108A91E0F2A038AEE70@CEZ.ICE","subject":"Re: git-PS1 bash prompt setting","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2006-11-26T15:18:05Z","receivedAt":"2006-11-26T15:18:05Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sun, 26 Nov 2006, Sean wrote:\n\n> On Sun, 26 Nov 2006 15:27:07 +0100 (CET)\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> \n> > But there really is no good place to put it: most commands need a git \n> > repository, and those which do not, are inappropriate to put an option \n> > \"--show-ps1\" into. Except maybe repo-config. Thoughts?\n> \n> What about just making it an option to the git wrapper?\n\nD'oh. Too easy!\n\nThanks,\nDscho\n"},{"id":"294013","messageId":"20061127065400.GA19174@spearce.org","threadId":"43077","inReplyTo":"20061126094212.fde8cce7.seanlkml@sympatico.ca","subject":"Re: git-PS1 bash prompt setting","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-11-27T06:54:00Z","receivedAt":"2006-11-27T06:54:00Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Sean <seanlkml@sympatico.ca> wrote:\n> On Sun, 26 Nov 2006 15:27:07 +0100 (CET)\n> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n> \n> > But there really is no good place to put it: most commands need a git \n> > repository, and those which do not, are inappropriate to put an option \n> > \"--show-ps1\" into. Except maybe repo-config. Thoughts?\n> \n> What about just making it an option to the git wrapper?\n\nI'm using something like this, and will be adding it to\ngit-completion.bash tonight:\n\n\t__git_ps1 ()\n\t{\n\t\tlocal b=\"$(git symbolic-ref HEAD 2>/dev/null)\"\n\t\tif [ -n \"$b\" ]; then echo \"(${b##refs/heads/})\"; fi\n\t}\n\tPS1='[\\u@\\h \\W$(__git_ps1)]\\$ '\n\nit works very well...\n\n-- \n"},{"id":"296128","messageId":"eke571$ng2$1@sea.gmane.org","threadId":"43077","inReplyTo":"20061127065400.GA19174@spearce.org","subject":"Re: git-PS1 bash prompt setting","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2006-11-27T07:49:31Z","receivedAt":"2006-11-27T07:49:31Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Shawn Pearce wrote:\n\n> Sean <seanlkml@sympatico.ca> wrote:\n>> On Sun, 26 Nov 2006 15:27:07 +0100 (CET)\n>> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:\n>> \n>>> But there really is no good place to put it: most commands need a git \n>>> repository, and those which do not, are inappropriate to put an option \n>>> \"--show-ps1\" into. Except maybe repo-config. Thoughts?\n>> \n>> What about just making it an option to the git wrapper?\n> \n> I'm using something like this, and will be adding it to\n> git-completion.bash tonight:\n> \n>       __git_ps1 ()\n>       {\n>               local b=\"$(git symbolic-ref HEAD 2>/dev/null)\"\n>               if [ -n \"$b\" ]; then echo \"(${b##refs/heads/})\"; fi\n>       }\n>       PS1='[\\u@\\h \\W$(__git_ps1)]\\$ '\n> \n> it works very well...\n\nPerhaps, as it was proposed somewhere else in this thread, instead of\n\\u@\\h use $(git repo-config --get user.email)?\n\nAnd I would add \\!: at the beginning of prompt, but that might be\njust me.\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n\n"},{"id":"295483","messageId":"7vy7pxjmw7.fsf@assigned-by-dhcp.cox.net","threadId":"43077","inReplyTo":"20061126150523.GB18828@hermes.lan.home.vilz.de","subject":"Re: git-PS1 bash prompt setting","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-11-27T08:48:24Z","receivedAt":"2006-11-27T08:48:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nicolas Vilz <niv@iaglans.de> writes:\n\n> I glued that in my system bashrc with the extension, that it shows to me\n> user.email out of repo-config, which is also very handy. So I am always\n> reminded to set my user.credentials in .git/config and i always know which \n> role i play in the repository i am working at.\n\nI think there is something wrong if the user needs to be\n_constantly_ reminded who he is.  Care to explain?\n\nThere was a talk on the list about making \"git-commit\" (and\n\"git-merge\" that does not do a fast-forward) refuse to proceed\nuntil user.nameemail are explicitly set in the configuration.  I\nthink that particular implementation is a bad idea because it\npunishes people who have set up their GECOS and hostname sanely,\nbut at the same time I do understand that people who just\nstarted to use git would be very unhappy to learn that their\nnames were misspelled in GECOS field only after accumulating a\ncouple dozen commits.\n\n"},{"id":"295827","messageId":"20061127105047.GB5428@fry.bender.fht","threadId":"43077","inReplyTo":"7vy7pxjmw7.fsf@assigned-by-dhcp.cox.net","subject":"Re: git-PS1 bash prompt setting","fromName":"Nicolas Vilz","fromEmail":"niv@iaglans.de","sentAt":"2006-11-27T10:50:47Z","receivedAt":"2006-11-27T10:50:47Z","isPatch":false,"sender":{"key":"niv@iaglans.de","avatar":"https://gravatar.com/avatar/e4d43a32d721241212d4edb1d2210327e28423c913071b4bfeeaa0ce15296110?d=mp&s=160"},"body":"On Mon, Nov 27, 2006 at 12:48:24AM -0800, Junio C Hamano wrote:\n> Nicolas Vilz <niv@iaglans.de> writes:\n> \n> > I glued that in my system bashrc with the extension, that it shows to me\n> > user.email out of repo-config, which is also very handy. So I am always\n> > reminded to set my user.credentials in .git/config and i always know which \n> > role i play in the repository i am working at.\n> \n> I think there is something wrong if the user needs to be\n> _constantly_ reminded who he is.  Care to explain?\n\nYes, you are right. It sounds a bit strange. I try to setup a pool of \nconfiguration data for several linux-boxes which are kind of equal in a \ngit repository.\n\nNormally I just pull the config-branch from the repository to the\nparticular box, but sometimes i have to test the config and alter it...\nand other people do as well. And therefore i like to be reminded\nconstantly who I am.\n\nI glued that in the system bashrc, so I have it for services which\nrun as users and which configuration data has to be edited by the\nservices user... also here, several people are working on that machine\nand make changes.\n\nSincerly\n"},{"id":"294231","messageId":"BAYC1-PASMTP023A7249055A08208223F1AEE60@CEZ.ICE","threadId":"43077","inReplyTo":"20061127065400.GA19174@spearce.org","subject":"Re: git-PS1 bash prompt setting","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2006-11-27T12:56:50Z","receivedAt":"2006-11-27T12:56:50Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Mon, 27 Nov 2006 01:54:00 -0500\nShawn Pearce <spearce@spearce.org> wrote:\n\n> I'm using something like this, and will be adding it to\n> git-completion.bash tonight:\n> \n> \t__git_ps1 ()\n> \t{\n> \t\tlocal b=\"$(git symbolic-ref HEAD 2>/dev/null)\"\n> \t\tif [ -n \"$b\" ]; then echo \"(${b##refs/heads/})\"; fi\n> \t}\n> \tPS1='[\\u@\\h \\W$(__git_ps1)]\\$ '\n> \n> it works very well...\n\nYeah, when I first coded it I even looked at making it a bash loadable\nto make it perform better but found the prototype to run acceptably,\nso never bothered.   If Git does get a --show-ps1 option, people will\nstill be able to roll their own version to tweak the output format\nas you did above.  Hopefully the standard format will work for most\nthough.\n\n"},{"id":"298285","messageId":"20061127170249.GC6616@spearce.org","threadId":"43077","inReplyTo":"20061127075650.81a5a850.seanlkml@sympatico.ca","subject":"Re: git-PS1 bash prompt setting","fromName":"Shawn Pearce","fromEmail":"spearce@spearce.org","sentAt":"2006-11-27T17:02:49Z","receivedAt":"2006-11-27T17:02:49Z","isPatch":false,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Sean <seanlkml@sympatico.ca> wrote:\n> On Mon, 27 Nov 2006 01:54:00 -0500\n> Shawn Pearce <spearce@spearce.org> wrote:\n> \n> > I'm using something like this, and will be adding it to\n> > git-completion.bash tonight:\n> > \n> > \t__git_ps1 ()\n> > \t{\n> > \t\tlocal b=\"$(git symbolic-ref HEAD 2>/dev/null)\"\n> > \t\tif [ -n \"$b\" ]; then echo \"(${b##refs/heads/})\"; fi\n> > \t}\n> > \tPS1='[\\u@\\h \\W$(__git_ps1)]\\$ '\n> > \n> > it works very well...\n> \n> Yeah, when I first coded it I even looked at making it a bash loadable\n> to make it perform better but found the prototype to run acceptably,\n> so never bothered.\n\nWhen I originally coded the first version of __git_ps1 I was using\nit on a Cygwin system, where the fork+exec of the external script\ncan take a little while.  The time to fork+exec two programs (script\nand then git) is huge compared to just fork+exec of git by itself,\nso I coded it as a function.  On the other hand my Mac OS X system\ndoesn't even blink at either implementation.\n\n> If Git does get a --show-ps1 option, people will\n> still be able to roll their own version to tweak the output format\n> as you did above.  Hopefully the standard format will work for most\n> though.\n\nI'm not sure that's worth implementing in the core code.\nMost shells that will let you invoke a command as part of their\nprompt generation will also let you use builtin functions and do\nsome basic string manipulation (e.g. like I do above with bash).\nAt which point it is say 5 lines of shell (nicely formatted) to\ncraft a prompt string vs. 15-20 lines of C to parse the option,\nread HEAD, and craft a prompt string.\n\nIf someone else contributes a --show-ps1 option that is useable as\na replacement for my __git_ps1 I'll gladly jump on board and change\nto using it, but I just don't see a reason to write it myself.\n\n-- \n"},{"id":"296927","messageId":"BAYC1-PASMTP0709A31FDE4B0DBA4174E9AEE60@CEZ.ICE","threadId":"43077","inReplyTo":"20061127170249.GC6616@spearce.org","subject":"Re: git-PS1 bash prompt setting","fromName":"Sean","fromEmail":"seanlkml@sympatico.ca","sentAt":"2006-11-27T17:38:30Z","receivedAt":"2006-11-27T17:38:30Z","isPatch":false,"sender":{"key":"seanlkml@sympatico.ca","avatar":"https://gravatar.com/avatar/f92923f54fc08c401fc59b71829d4b89e9b8087fbba45ff87c82e6a83aee02ae?d=mp&s=160"},"body":"On Mon, 27 Nov 2006 12:02:49 -0500\nShawn Pearce <spearce@spearce.org> wrote:\n\n> When I originally coded the first version of __git_ps1 I was using\n> it on a Cygwin system, where the fork+exec of the external script\n> can take a little while.  The time to fork+exec two programs (script\n> and then git) is huge compared to just fork+exec of git by itself,\n> so I coded it as a function.  On the other hand my Mac OS X system\n> doesn't even blink at either implementation.\n\nFor sure, that's probably the reason that it was suggested to be\nincluded as a built-in, it would reduce the overhead.\n\n> I'm not sure that's worth implementing in the core code.\n> Most shells that will let you invoke a command as part of their\n> prompt generation will also let you use builtin functions and do\n> some basic string manipulation (e.g. like I do above with bash).\n> At which point it is say 5 lines of shell (nicely formatted) to\n> craft a prompt string vs. 15-20 lines of C to parse the option,\n> read HEAD, and craft a prompt string.\n\nWell, as per my previous message, it might be a little more worthwhile\nif it did things like parse an additional format string which let\nyou reference config variables and relative directory etc.\nIt would give a lot of flexibility as to what someone wanted to\nuse as their PS1 when inside a git repo.\n \n> If someone else contributes a --show-ps1 option that is useable as\n> a replacement for my __git_ps1 I'll gladly jump on board and change\n> to using it, but I just don't see a reason to write it myself.\n\nYeah.. __git_ps1 could just call \"git --show-ps1\" if it ever comes\ninto existence ;o)\n\n"}]}