From: Junio C Hamano <gitster@pobox.com>
To: Thomas Rast <trast@inf.ethz.ch>
Cc: "SZEDER Gábor" <szeder@ira.uka.de>,
"Ted Pavlic" <ted@tedpavlic.com>,
"Felipe Contreras" <felipe.contreras@gmail.com>,
"Ville Skyttä" <ville.skytta@iki.fi>,
"Thomas Rast" <trast@student.ethz.ch>,
"Kerrick Staley" <mail@kerrickstaley.com>,
"Dan McGee" <dan@archlinux.org>,
"Zbigniew Jędrzejewski-Szmek" <zbyszek@in.waw.pl>,
git@vger.kernel.org, "Marius Storm-Olsen" <mstormo@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH 2/2] completion: split __git_ps1 into a separate script
Date: Fri, 25 May 2012 11:03:14 -0700 [thread overview]
Message-ID: <7v8vggt9y5.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <87ehq8its8.fsf@thomas.inf.ethz.ch> (Thomas Rast's message of "Fri, 25 May 2012 09:50:15 +0200")
Thomas Rast <trast@inf.ethz.ch> writes:
> Why not make a git builtin command that figures out everything that
> __git_ps1 does? Perhaps in a format that can be eval'd and processed to
> the user's taste.
I'd rather not to see something so specific for one interpreter like that
in the core. How about doing it this way instead?
diff --git a/contrib/completion/Makefile b/contrib/completion/Makefile
new file mode 100644
index 0000000..71c600f
--- /dev/null
+++ b/contrib/completion/Makefile
@@ -0,0 +1,13 @@
+# The default target is ...
+all::
+
+SCRIPTS = git-completion.bash git-prompt.sh
+
+all:: $(SCRIPTS)
+clean::
+ rm -f $(SCRIPTS)
+
+$(SCRIPTS): % : %.shc
+ rm -f $@+ $@
+ sed -e '/## include common-bits/r common-bits' $< >$@+
+ mv $@+ $@
diff --git a/contrib/completion/common-bits b/contrib/completion/common-bits
new file mode 100644
index 0000000..06c2845
--- /dev/null
+++ b/contrib/completion/common-bits
@@ -0,0 +1,22 @@
+# __gitdir accepts 0 or 1 arguments (i.e., location)
+# returns location of .git repo
+__gitdir ()
+{
+ if [ -z "${1-}" ]; then
+ if [ -n "${__git_dir-}" ]; then
+ echo "$__git_dir"
+ elif [ -n "${GIT_DIR-}" ]; then
+ test -d "${GIT_DIR-}" || return 1
+ echo "$GIT_DIR"
+ elif [ -d .git ]; then
+ echo .git
+ else
+ git rev-parse --git-dir 2>/dev/null
+ fi
+ elif [ -d "$1/.git" ]; then
+ echo "$1/.git"
+ else
+ echo "$1"
+ fi
+}
+
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash.shc
similarity index 99%
rename from contrib/completion/git-completion.bash
rename to contrib/completion/git-completion.bash.shc
index abf8215..cf30f01 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash.shc
@@ -32,24 +32,8 @@ case "$COMP_WORDBREAKS" in
*) COMP_WORDBREAKS="$COMP_WORDBREAKS:"
esac
-# __gitdir accepts 0 or 1 arguments (i.e., location)
-# returns location of .git repo
-__gitdir ()
-{
- if [ -z "${1-}" ]; then
- if [ -n "${__git_dir-}" ]; then
- echo "$__git_dir"
- elif [ -d .git ]; then
- echo .git
- else
- git rev-parse --git-dir 2>/dev/null
- fi
- elif [ -d "$1/.git" ]; then
- echo "$1/.git"
- else
- echo "$1"
- fi
-}
+## include common-bits here
+## common-bits ends here
__gitcomp_1 ()
{
diff --git a/contrib/completion/git-prompt.sh b/contrib/completion/git-prompt.sh.shc
similarity index 94%
rename from contrib/completion/git-prompt.sh
rename to contrib/completion/git-prompt.sh.shc
index 8e2e9f3..d442a1a 100644
--- a/contrib/completion/git-prompt.sh
+++ b/contrib/completion/git-prompt.sh.shc
@@ -49,27 +49,8 @@
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
# setting the bash.showUpstream config variable.
-# __gitdir accepts 0 or 1 arguments (i.e., location)
-# returns location of .git repo
-__gitdir ()
-{
- if [ -z "${1-}" ]; then
- if [ -n "${__git_dir-}" ]; then
- echo "$__git_dir"
- elif [ -n "${GIT_DIR-}" ]; then
- test -d "${GIT_DIR-}" || return 1
- echo "$GIT_DIR"
- elif [ -d .git ]; then
- echo .git
- else
- git rev-parse --git-dir 2>/dev/null
- fi
- elif [ -d "$1/.git" ]; then
- echo "$1/.git"
- else
- echo "$1"
- fi
-}
+## include common-bits here
+## common-bits ends here
# stores the divergence from upstream in $p
# used by GIT_PS1_SHOWUPSTREAM
next prev parent reply other threads:[~2012-05-25 18:03 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-22 20:46 [PATCH 0/2] completion: split into git-prompt.sh Felipe Contreras
2012-05-22 20:46 ` [PATCH 1/2] completion: remove executable mode Felipe Contreras
2012-05-22 20:46 ` [PATCH 2/2] completion: split __git_ps1 into a separate script Felipe Contreras
2012-05-22 21:07 ` Zbigniew Jędrzejewski-Szmek
2012-05-22 22:29 ` Ted Pavlic
2012-05-23 11:56 ` Felipe Contreras
2012-05-23 11:59 ` Felipe Contreras
2012-05-23 14:54 ` Junio C Hamano
2012-05-23 15:40 ` Felipe Contreras
2012-05-23 16:30 ` Junio C Hamano
2012-05-23 17:03 ` Ted Pavlic
2012-05-23 20:50 ` Felipe Contreras
2012-05-23 21:55 ` Ted Pavlic
2012-05-24 20:35 ` SZEDER Gábor
[not found] ` <CAOnadRFbrhrFz7Ya3Vhgsju9G723Qu0OdJnM31xFmBqQNgj6gA@mail.gmail.com>
2012-05-25 7:35 ` SZEDER Gábor
2012-05-25 7:50 ` Thomas Rast
2012-05-25 10:01 ` Felipe Contreras
2012-05-25 18:03 ` Junio C Hamano [this message]
2012-05-24 20:49 ` SZEDER Gábor
2012-05-22 22:27 ` Ted Pavlic
2012-05-23 11:53 ` Felipe Contreras
2012-05-23 14:59 ` Junio C Hamano
2012-05-24 20:47 ` SZEDER Gábor
2012-05-25 17:51 ` Ville Skyttä
2012-10-25 0:51 ` Where should git-prompt.sh be installed? Jonathan Nieder
2012-10-25 1:59 ` Drew Northup
2012-10-25 6:02 ` Danny Yates
2012-10-25 7:45 ` [RFC/PATCH] __git_ps1: migrate out of contrib/completion Jonathan Nieder
2012-10-25 14:19 ` Felipe Contreras
2012-11-08 13:19 ` Todd Zullinger
2012-10-25 8:10 ` Where should git-prompt.sh be installed? Anders Kaseorg
2012-10-25 15:11 ` SZEDER Gábor
2012-10-25 16:12 ` Jonathan Nieder
2012-05-23 16:33 ` [PATCH 0/2] completion: split into git-prompt.sh Junio C Hamano
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7v8vggt9y5.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=dan@archlinux.org \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=mail@kerrickstaley.com \
--cc=mstormo@gmail.com \
--cc=szeder@ira.uka.de \
--cc=ted@tedpavlic.com \
--cc=trast@inf.ethz.ch \
--cc=trast@student.ethz.ch \
--cc=ville.skytta@iki.fi \
--cc=zbyszek@in.waw.pl \
/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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).