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: Junio C Hamano <gitster@pobox.com>,
	"Shawn O. Pearce" <spearce@spearce.org>
Cc: "Jonathan Nieder" <jrnieder@gmail.com>,
	git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH 1/2] bash: add helper function to get config variables for completion
Date: Thu, 14 Oct 2010 10:58:46 +0200	[thread overview]
Message-ID: <1287046727-22509-1-git-send-email-szeder@ira.uka.de> (raw)
In-Reply-To: <20101014085538.GB838@neumann>

Currently there are three completion functions that perform similar
queries to 'git config' to get config variable names.  These are the
completion of aliases, remotes, and remote groups for 'git remote
update'.  Since the following patch is about to add yet another
similar 'git config'-querying completion function to support pretty
aliases, it's time to introduce a unified helper function first to
avoid redundant code.

We took care that the resulting helper function still copes well with
newlines in config variable values and that it works with 'set -u'
(see commits e0d7805 (completion: fix alias listings with newlines,
2009-10-08) and 25a31f8 (bash-completion: Support running when set -u
is enabled, 2009-01-15) for details).

Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
 contrib/completion/git-completion.bash |   28 +++++++++++-----------------
 1 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index f83f019..97a3d8c 100755
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -451,10 +451,7 @@ __git_remotes ()
 		echo ${i#$d/remotes/}
 	done
 	[ "$ngoff" ] && shopt -u nullglob
-	for i in $(git --git-dir="$d" config --get-regexp 'remote\..*\.url' 2>/dev/null); do
-		i="${i#remote.}"
-		echo "${i/.url*/}"
-	done
+	__git_get_config_variables "remote" "url"
 }
 
 __git_list_merge_strategies ()
@@ -750,14 +747,16 @@ __git_compute_porcelain_commands ()
 	: ${__git_porcelain_commands:=$(__git_list_porcelain_commands)}
 }
 
-__git_aliases ()
+# returns all config variables within a given section with an optional
+# suffix, with both the section name and the suffix removed
+__git_get_config_variables ()
 {
-	local i IFS=$'\n'
-	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "alias\..*" 2>/dev/null); do
+	local section="$1" suffix="${2-}" i IFS=$'\n'
+	for i in $(git --git-dir="$(__gitdir)" config --get-regexp "$section\..*${suffix:+\.$suffix}" 2>/dev/null); do
 		case "$i" in
-		alias.*)
-			i="${i#alias.}"
-			echo "${i/ */}"
+		$section.*)
+			i="${i#$section.}"
+			echo "${i/${suffix:+.$suffix} */}"
 			;;
 		esac
 	done
@@ -2017,12 +2016,7 @@ _git_remote ()
 		__gitcomp "$(__git_remotes)"
 		;;
 	update)
-		local i c='' IFS=$'\n'
-		for i in $(git --git-dir="$(__gitdir)" config --get-regexp "remotes\..*" 2>/dev/null); do
-			i="${i#remotes.}"
-			c="$c ${i/ */}"
-		done
-		__gitcomp "$c"
+		__gitcomp "$(__git_get_config_variables "remotes")"
 		;;
 	*)
 		COMPREPLY=()
@@ -2366,7 +2360,7 @@ _git ()
 			"
 			;;
 		*)     __git_compute_porcelain_commands
-		       __gitcomp "$__git_porcelain_commands $(__git_aliases)" ;;
+		       __gitcomp "$__git_porcelain_commands $(__git_get_config_variables "alias")" ;;
 		esac
 		return
 	fi
-- 
1.7.3.1.151.g3779c

  reply	other threads:[~2010-10-14  8:59 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-10 21:34 [PATCH] bash: support pretty format aliases SZEDER Gábor
2010-10-10 21:44 ` Jonathan Nieder
2010-10-10 22:06   ` [PATCH v2] " SZEDER Gábor
2010-10-14  8:55     ` SZEDER Gábor
2010-10-14  8:58       ` SZEDER Gábor [this message]
2010-10-14 17:15         ` [PATCH 1/2] bash: add helper function to get config variables for completion Jonathan Nieder
2010-10-20 22:29           ` SZEDER Gábor
2010-10-14  8:58       ` [PATCH 2/2] bash: support pretty format aliases SZEDER Gábor

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=1287046727-22509-1-git-send-email-szeder@ira.uka.de \
    --to=szeder@ira.uka.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.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).