git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Jonathan Nieder <jrnieder@gmail.com>
Cc: Peter van der Does <peter@avirtualhome.com>,
	"Shawn O. Pearce" <spearce@spearce.org>,
	git@vger.kernel.org, Marc Branchaud <marcnarc@xiplink.com>,
	Brian Gernhardt <brian@gernhardtsoftware.com>,
	Kevin Ballard <kevin@sb.org>,
	Mathias Lafeldt <misfire@debugon.org>
Subject: Re: [RFC/PATCH 2/1] bash: eliminate dependency on bash_completion lib
Date: Tue, 7 Dec 2010 17:07:48 +0100	[thread overview]
Message-ID: <20101207160747.GD1867@neumann> (raw)
In-Reply-To: <20101202210207.GA4994@burratino>

Hi Jonathan,

What is this patch based on?


Thanks,
Gábor


On Thu, Dec 02, 2010 at 03:02:07PM -0600, Jonathan Nieder wrote:
> Add a minimal implementation of _get_comp_words_by_ref,
> the routine used to work around bash 4.0's COMP_WORDS semantics.
> 
> Based on bash-completion 2.x (commit bf763033, 2010-10-26) but
> tweaked for simplicity and to allow zsh to at least parse the
> code.
> 
> Based-on-patch-by: Peter van der Does <peter@avirtualhome.com>
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
> ---
> Peter van der Does wrote:
> > Jonathan Nieder <jrnieder@gmail.com> wrote:
> 
> >>  2. Import the definition of _get_comp_words_by_ref from the
> >>     bash-completion lib and use it if ZSH_VERSION is unset.
> >> 
> >>  3. Further refinements, if needed.
> >> 
> >> What do you think?
> >
> > I like the idea and we should go with this solution.
> > 
> > If by importing you mean using :
> > [CODE]. /git_bash_completion-functions[/CODE] in the
> > contrib/completion/git-completion.bash script, which would be the best
> > solution imho. The question is where to place that the function file.
> [...]
> > It would have to include copying the functions file somewhere as well.
> > 
> > Or we could use the method used now and include the functions in the
> > git-completion.bash script.
> 
> Sorry for the lack of clarity.  Here's what I meant.
> 
>  contrib/completion/git-completion.bash |  125 ++++++++++++++++++++++++++++++++
>  1 files changed, 125 insertions(+), 0 deletions(-)
> 
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 0b0eb45..1743319 100755
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -327,7 +327,102 @@ __gitcomp_1 ()
>  	done
>  }
>  
> +# The following function is based on code from:
> +#
> +#   bash_completion - programmable completion functions for bash 3.2+
> +#
> +#   Copyright © 2006-2008, Ian Macdonald <ian@caliban.org>
> +#             © 2009-2010, Bash Completion Maintainers
> +#                     <bash-completion-devel@lists.alioth.debian.org>
> +#
> +#   This program is free software; you can redistribute it and/or modify
> +#   it under the terms of the GNU General Public License as published by
> +#   the Free Software Foundation; either version 2, or (at your option)
> +#   any later version.
> +#
> +#   This program is distributed in the hope that it will be useful,
> +#   but WITHOUT ANY WARRANTY; without even the implied warranty of
> +#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +#   GNU General Public License for more details.
> +#
> +#   You should have received a copy of the GNU General Public License
> +#   along with this program; if not, write to the Free Software Foundation,
> +#   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
> +#
> +#   The latest version of this software can be obtained here:
> +#
> +#   http://bash-completion.alioth.debian.org/
> +#
> +#   RELEASE: 2.x
> +
> +# This function can be used to access a tokenized list of words
> +# on the command line:
> +#
> +#	__reassemble_comp_words_by_ref '=:'
> +#	if test "${words_[cword_-1]}" = -w
> +#	then
> +#		...
> +#	fi
> +#
> +# The argument should be a collection of characters from the list of
> +# word completion separators (COMP_WORDBREAKS) to treat as ordinary
> +# characters.
> +#
> +# This is roughly equivalent to locally setting COMP_WORDBREAKS to
> +# exclude those characters, but it does not clobber COMP_WORDBREAKS.
> +# The intent is for it to be used by commands like ssh that want to
> +# treat host:path as one token.
> +#
> +# Output: words_, cword_, cur_.
> +
> +__git_reassemble_comp_words_by_ref()
> +{
> +	local exclude i j first
> +	# Which word separators to exclude?
> +	exclude="${1//[^$COMP_WORDBREAKS]}"
> +	cword_=$COMP_CWORD
> +	if [ -z "$exclude" ]; then
> +		words_=("${COMP_WORDS[@]}")
> +		return
> +	fi
> +	# List of word completion separators has shrunk;
> +	# re-assemble words to complete.
> +	for ((i=0, j=0; i < ${#COMP_WORDS[@]}; i++, j++)); do
> +		# Append each nonempty word consisting of just
> +		# word separator characters to the current word.
> +		first=t
> +		while
> +			[ $i -gt 0 ] &&
> +			[ -n "${COMP_WORDS[$i]}" ] &&
> +			# word consists of excluded word separators
> +			[ "${COMP_WORDS[$i]//[^$exclude]}" = "${COMP_WORDS[$i]}" ]
> +		do
> +			# Attach to the previous token,
> +			# unless the previous token is the command name.
> +			if [ $j -ge 2 ] && [ -n "$first" ]; then
> +				((j--))
> +			fi
> +			first=
> +			words_[$j]=${words_[j]}${COMP_WORDS[i]}
> +			if [ $i = $COMP_CWORD ]; then
> +				cword_=$j
> +			fi
> +			if (($i < ${#COMP_WORDS[@]} - 1)); then
> +				((i++))
> +			else
> +				# Done.
> +				return
> +			fi
> +		done
> +		words_[$j]=${words_[j]}${COMP_WORDS[i]}
> +		if [ $i = $COMP_CWORD ]; then
> +			cword_=$j
> +		fi
> +	done
> +}
> +
>  if ! type _get_comp_words_by_ref >/dev/null 2>&1; then
> +if [[ -n $ZSH_VERSION ]]; then
>  _get_comp_words_by_ref ()
>  {
>  	while [ $# -gt 0 ]; do
> @@ -352,6 +447,36 @@ _get_comp_words_by_ref ()
>  		shift
>  	done
>  }
> +else
> +_get_comp_words_by_ref ()
> +{
> +	local exclude cur_ cword_
> +	local words_=()
> +	if [ "$1" = "-n" ]; then
> +		exclude=$2
> +		shift 2
> +	fi
> +	__git_reassemble_comp_words_by_ref "$exclude"
> +	cur_=${words_[cword_]}
> +	while [ $# -gt 0 ]; do
> +		case "$1" in
> +		cur)
> +			cur=$cur_
> +			;;
> +		prev)
> +			prev=${words_[$cword_-1]}
> +			;;
> +		words)
> +			words=("${words_[@]}")
> +			;;
> +		cword)
> +			cword=$cword_
> +			;;
> +		esac
> +		shift
> +	done
> +}
> +fi
>  fi
>  
>  # __gitcomp accepts 1, 2, 3, or 4 arguments
> -- 
> 1.7.2.3
> 

  parent reply	other threads:[~2010-12-07 16:23 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-12-01 20:49 [PATCH v4 0/2] *** SUBJECT HERE *** Peter van der Does
2010-12-01 20:49 ` [PATCH v4 1/2] Introduce functions from bash-completion project Peter van der Does
2010-12-01 20:49 ` [PATCH v4 2/2] Use the new functions to get the current cword Peter van der Does
2010-12-02  7:45   ` Jonathan Nieder
2010-12-02 22:36   ` SZEDER Gábor
2010-12-01 21:09 ` [PATCH v4 0/2] Make git-completion Bash 4 compatible Jonathan Nieder
2010-12-02  1:10 ` SZEDER Gábor
2010-12-02  9:16 ` Jonathan Nieder
2010-12-02 14:16   ` Peter van der Does
2010-12-02 21:02     ` [RFC/PATCH 2/1] bash: eliminate dependency on bash_completion lib Jonathan Nieder
2010-12-02 23:40       ` SZEDER Gábor
2010-12-03  0:07         ` Jonathan Nieder
2010-12-03  8:02         ` Stephen Boyd
2010-12-07 16:07       ` SZEDER Gábor [this message]
2010-12-07 19:49         ` Jonathan Nieder
2010-12-07 20:41           ` SZEDER Gábor
2010-12-07 20:59             ` Jonathan Nieder
2010-12-07 21:03           ` Junio C Hamano
2010-12-15  6:24             ` [PATCH v5.1 0/3] Make git-completion Bash 4 compatible Jonathan Nieder
2010-12-15  6:26               ` [PATCH 1/3] bash: get --pretty=m<tab> completion to work with bash v4 Jonathan Nieder
2010-12-15  6:27               ` [PATCH 2/3] bash: simple reimplementation of _get_comp_words_by_ref Jonathan Nieder
2010-12-15  6:42               ` [MERGE PATCH 3/3] Merge branch 'master' (early part) into pd/bash-4-completion Jonathan Nieder

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=20101207160747.GD1867@neumann \
    --to=szeder@ira.uka.de \
    --cc=brian@gernhardtsoftware.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=kevin@sb.org \
    --cc=marcnarc@xiplink.com \
    --cc=misfire@debugon.org \
    --cc=peter@avirtualhome.com \
    --cc=spearce@spearce.org \
    /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).