From: Shawn Pearce <spearce@spearce.org>
To: Sean <seanlkml@sympatico.ca>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
git@vger.kernel.org, Theodore Tso <tytso@mit.edu>
Subject: Re: git-PS1 bash prompt setting
Date: Mon, 27 Nov 2006 12:02:49 -0500 [thread overview]
Message-ID: <20061127170249.GC6616@spearce.org> (raw)
In-Reply-To: <20061127075650.81a5a850.seanlkml@sympatico.ca>
Sean <seanlkml@sympatico.ca> wrote:
> On Mon, 27 Nov 2006 01:54:00 -0500
> Shawn Pearce <spearce@spearce.org> wrote:
>
> > I'm using something like this, and will be adding it to
> > git-completion.bash tonight:
> >
> > __git_ps1 ()
> > {
> > local b="$(git symbolic-ref HEAD 2>/dev/null)"
> > if [ -n "$b" ]; then echo "(${b##refs/heads/})"; fi
> > }
> > PS1='[\u@\h \W$(__git_ps1)]\$ '
> >
> > it works very well...
>
> Yeah, when I first coded it I even looked at making it a bash loadable
> to make it perform better but found the prototype to run acceptably,
> so never bothered.
When I originally coded the first version of __git_ps1 I was using
it on a Cygwin system, where the fork+exec of the external script
can take a little while. The time to fork+exec two programs (script
and then git) is huge compared to just fork+exec of git by itself,
so I coded it as a function. On the other hand my Mac OS X system
doesn't even blink at either implementation.
> If Git does get a --show-ps1 option, people will
> still be able to roll their own version to tweak the output format
> as you did above. Hopefully the standard format will work for most
> though.
I'm not sure that's worth implementing in the core code.
Most shells that will let you invoke a command as part of their
prompt generation will also let you use builtin functions and do
some basic string manipulation (e.g. like I do above with bash).
At which point it is say 5 lines of shell (nicely formatted) to
craft a prompt string vs. 15-20 lines of C to parse the option,
read HEAD, and craft a prompt string.
If someone else contributes a --show-ps1 option that is useable as
a replacement for my __git_ps1 I'll gladly jump on board and change
to using it, but I just don't see a reason to write it myself.
--
next prev parent reply other threads:[~2006-11-27 17:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-16 18:01 git-PS1 bash prompt setting Sean
2006-11-16 18:35 ` Junio C Hamano
2006-11-26 14:27 ` Johannes Schindelin
2006-11-26 14:42 ` Sean
2006-11-26 15:18 ` Johannes Schindelin
[not found] ` <20061126094212.fde8cce7.seanlkml@sympatico.ca>
2006-11-26 15:05 ` Nicolas Vilz
2006-11-27 8:48 ` Junio C Hamano
2006-11-27 10:50 ` Nicolas Vilz
2006-11-27 6:54 ` Shawn Pearce
2006-11-27 7:49 ` Jakub Narebski
2006-11-27 12:56 ` Sean
[not found] ` <20061127075650.81a5a850.seanlkml@sympatico.ca>
2006-11-27 17:02 ` Shawn Pearce [this message]
2006-11-27 17:38 ` Sean
[not found] <20061116130111.921396df.seanlkml@sympatico.ca>
2006-11-17 8:38 ` Nicolas Vilz
2006-11-17 9:20 ` Sean
2006-11-19 6:28 ` Junio C Hamano
[not found] ` <20061117042051.d2fbddb6.seanlkml@sympatico.ca>
2006-11-17 9:52 ` Nicolas Vilz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20061127170249.GC6616@spearce.org \
--to=spearce@spearce.org \
--cc=Johannes.Schindelin@gmx.de \
--cc=git@vger.kernel.org \
--cc=seanlkml@sympatico.ca \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).