git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] fixup! doc: generate a list of valid merge tools

From
John Keeping <john@keeping.me.uk>
Date
Jan 30, 2013, 19:55 UTC
Message-ID
<ab68c2d04aa2177a303c53517219cff8a82d8db5.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 | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)
diff --git a/git-mergetool--lib.sh b/git-mergetool--lib.sh
index b6ed2fa..b44a2c8 100644
--- a/git-mergetool--lib.sh
+++ b/git-mergetool--lib.sh
@@ -22,6 +22,7 @@ is_available () {
 
 show_tool_names () {
 	condition=${1:-true} per_line_prefix=${2:-} preamble=${3:-}
+	not_found_msg=${4:-}
 
 	shown_any=
 	( cd "$MERGE_TOOLS_DIR" && ls ) | {
@@ -32,13 +33,19 @@ show_tool_names () {
 			then
 				if test -n "$preamble"
 				then
-					echo "$preamble"
+					printf "%s\n" "$preamble"
 					preamble=
 				fi
 				shown_any=yes
 				printf "%s%s\n" "$per_line_prefix" "$toolname"
 			fi
 		done
+
+		if test -n "$preamble" && test -n "$not_found_msg"
+		then
+			printf "%s\n" "$not_found_msg"
+		fi
+
 		test -n "$shown_any"
 	}
 }
@@ -242,30 +249,27 @@ list_merge_tool_candidates () {
 show_tool_help () {
 	tool_opt="'git ${TOOL_MODE}tool --tool-<tool>'"
 
-	tab='	' av_shown= unav_shown=
+	tab='	'
+	LF='
+'
+	any_shown=no
 
 	cmd_name=${TOOL_MODE}tool
-	if show_tool_names 'mode_ok && is_available' "$tab$tab" \
-		"$tool_opt may be set to one of the following:"
-	then
-		av_shown=yes
-	else
-		echo "No suitable tool for 'git $cmd_name --tool=<tool>' found."
-		av_shown=no
-	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." &&
+		any_shown=yes
 
-	if show_tool_names 'mode_ok && ! is_available' "$tab$tab" \
-		"The following tools are valid, but not currently available:"
-	then
-		unav_shown=yes
-	fi
+	show_tool_names 'mode_ok && ! is_available' "$tab$tab" \
+		"${LF}The following tools are valid, but not currently available:" &&
+		any_shown=yes
 
-	case ",$av_shown,$unav_shown," in
-	*,yes,*)
+	if test "$any_shown" = yes
+	then
 		echo
 		echo "Some of the tools listed above only work in a windowed"
 		echo "environment. If run in a terminal-only session, they will fail."
-	esac
+	fi
 	exit 0
 }
 
-- 
1.8.1.1
Previous: John KeepingNext: John Keeping
Message 5 of 6 in “mergetool: add user configured commands to '--tool-help'”
  1. 0/3 mergetool: add user configured commands to '--tool-help'John Keeping, Jan 30, 2013
  2. 1/3 fixup! mergetool--lib: add functions for finding available toolsJohn Keeping, Jan 30, 2013
  3. Junio C HamanoJan 30, 2013
  4. John KeepingJan 30, 2013
  5. 2/3 fixup! doc: generate a list of valid merge toolsJohn Keeping, Jan 30, 2013
  6. 3/3 mergetool--lib: list user configured tools in '--tool-help'John Keeping, Jan 30, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.