git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Keeping <john@keeping.me.uk>
To: git@vger.kernel.org
Cc: David Aguilar <davvid@gmail.com>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 3/3] mergetool--lib: list user configured tools in '--tool-help'
Date: Wed, 30 Jan 2013 19:55:46 +0000	[thread overview]
Message-ID: <06855a92e18426f85f205341b6b5afba88e9ef3f.1359575447.git.john@keeping.me.uk> (raw)
In-Reply-To: <cover.1359575447.git.john@keeping.me.uk>
In-Reply-To: <cover.1359575447.git.john@keeping.me.uk>

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 git-mergetool--lib.sh | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index b44a2c8..e338be5 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -20,9 +20,24 @@ is_available () {
 	type "$merge_tool_path" >/dev/null 2>&1
 }
 
+list_config_tools () {
+	section=$1
+	line_prefix=${2:-}
+
+	git config --get-regexp $section'\..*\.cmd' |
+	while read -r key value
+	do
+		toolname=${key#$section.}
+		toolname=${toolname%.cmd}
+
+		printf "%s%s\n" "$line_prefix" "$toolname"
+	done
+}
+
 show_tool_names () {
 	condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-}
 	not_found_msg=${4:-}
+	extra_content=${5:-}
 
 	shown_any=
 	( cd "$MERGE_TOOLS_DIR" && ls ) | {
@@ -41,6 +56,19 @@ show_tool_names () {
 			fi
 		done
 
+		if test -n "$extra_content"
+		then
+			if test -n "$preamble"
+			then
+				# Note: no '\n' here since we don't want a
+				# blank line if there is no initial content.
+				printf "%s" "$preamble"
+				preamble=
+			fi
+			shown_any=yes
+			printf "\n%s\n" "$extra_content"
+		fi
+
 		if test -n "$preamble" && test -n "$not_found_msg"
 		then
 			printf "%s\n" "$not_found_msg"
@@ -255,9 +283,20 @@ show_tool_help () {
 	any_shown=no
 
 	cmd_name=${TOOL_MODE}tool
+	config_tools=$({
+		diff_mode && list_config_tools difftool "$tab$tab"
+		list_config_tools mergetool "$tab$tab"
+	} | sort)
+	extra_content=
+	if test -n "$config_tools"
+	then
+		extra_content="${tab}user-defined:${LF}$config_tools"
+	fi
+
 	show_tool_names 'mode_ok && is_available' "$tab$tab" \
 		"$tool_opt may be set to one of the following:" \
-		"No suitable tool for 'git $cmd_name --tool=<tool>' found." &&
+		"No suitable tool for 'git $cmd_name --tool=<tool>' found." \
+		"$extra_content" &&
 		any_shown=yes
 
 	show_tool_names 'mode_ok && ! is_available' "$tab$tab" \
-- 
1.8.1.1

      parent reply	other threads:[~2013-01-30 19:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-30 19:55 [PATCH 0/3] mergetool: add user configured commands to '--tool-help' John Keeping
2013-01-30 19:55 ` [PATCH 1/3] fixup! mergetool--lib: add functions for finding available tools John Keeping
2013-01-30 20:23   ` Junio C Hamano
2013-01-30 20:34     ` John Keeping
2013-01-30 19:55 ` [PATCH 2/3] fixup! doc: generate a list of valid merge tools John Keeping
2013-01-30 19:55 ` John Keeping [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=06855a92e18426f85f205341b6b5afba88e9ef3f.1359575447.git.john@keeping.me.uk \
    --to=john@keeping.me.uk \
    --cc=davvid@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).