diff --git a/Docs/mysql.info b/Docs/mysql.info
index 7747201..dffacfd 100644
--- a/Docs/mysql.info
+++ b/Docs/mysql.info
@@ -20512,6 +20512,8 @@ sequences.
 `\D'        The full current date
 `\d'        The default database
 `\h'        The server host
+`\H'        Same as `\h' except that if the server host is localhost
+            the client's hostname will be used
 `\l'        The current delimiter (new in 5.1.12)
 `\m'        Minutes of the current time
 `\n'        A newline character
diff --git a/client/mysql.cc b/client/mysql.cc
index 5f360b8..b24fb14 100644
--- a/client/mysql.cc
+++ b/client/mysql.cc
@@ -39,6 +39,10 @@
 #include <signal.h>
 #include <violite.h>
 
+#ifdef SOLARIS
+extern "C" int gethostname(char *name, int namelen);
+#endif
+
 #if defined(USE_LIBEDIT_INTERFACE) && defined(HAVE_LOCALE_H)
 #include <locale.h>
 #endif
@@ -4657,12 +4661,27 @@ static const char* construct_prompt()
       case 'd':
 	processed_prompt.append(current_db ? current_db : "(none)");
 	break;
+      /* \H is the same as \h except if \h returns localhost in which case *
+       * we provide the client's hostname.                                 *
+       */
       case 'h':
+      case 'H':
       {
 	const char *prompt;
+        char  myhostname[255];
 	prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
-	if (strstr(prompt, "Localhost"))
-	  processed_prompt.append("localhost");
+
+	if (strstr(prompt, "Localhost") || strstr(prompt, "localhost"))
+          if ( *c == 'h' ) {
+	    processed_prompt.append("localhost");
+          }
+          else
+          {
+            if (gethostname(myhostname,sizeof(myhostname)) < 0)
+              processed_prompt.append( "gethostname(3) returned an error" );
+            else
+              processed_prompt.append( myhostname );
+          }
 	else
 	{
 	  const char *end=strcend(prompt,' ');
