From: "Shawn O. Pearce" <spearce@spearce.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 4/8] bash: Add space after unique command name is completed.
Date: Sun, 4 Feb 2007 03:13:01 -0500 [thread overview]
Message-ID: <20070204081301.GE16766@spearce.org> (raw)
In-Reply-To: <7vr6t6xs3d.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> wrote:
> "Shawn O. Pearce" <spearce@spearce.org> writes:
>
> > +__gitcomp ()
> > +{
> > + local all c s=$'\n' IFS=' '$'\t'$'\n'
> > + for c in $1; do
> > + case "$c" in
> > + --*=*) all="$all$c$s" ;;
> > + *) all="$all$c $s" ;;
> > + esac
> > + done
> > + IFS=$s
> > + COMPREPLY=($(compgen -W "$all" -- "${COMP_WORDS[COMP_CWORD]}"))
> > + return
> > +}
> > +
>
> I do not understand what is going on here. Care to explain?
>
> (1) "for c in $1": because $1 is not dquoted, it is split into
> word with IFS -- which IFS applies to this splitting? The
> local one you hand-define to the typical " \t\n" value?
Correct.
> (2) when this function returns, what IFS value does the caller
> would have? Is the "local" used to avoid screwing up the
> caller?
>
Correct.
Basically at the time I'm forming 'all' I want $1 split based on
normal splitting rules, as I'm using space, tag and LF within the
script in some places for the first parameter to __gitcomp.
But when I run compgen I need IFS to be just LF ($s) so that $all
is split only on LF and not on spaces, as spaces were added to $all
after each unique option. This way the trailing space is part of
the unique option, and bash will tack in the trailing space for me,
despite having -o nospace enabled.
--
Shawn.
prev parent reply other threads:[~2007-02-04 8:13 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-02-04 7:38 [PATCH 4/8] bash: Add space after unique command name is completed Shawn O. Pearce
2007-02-04 8:08 ` Junio C Hamano
2007-02-04 8:13 ` Shawn O. Pearce [this message]
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=20070204081301.GE16766@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/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).