From eca060775e2465dd1be7f3bb252b308f05c937d0 Mon Sep 17 00:00:00 2001 From: Dan Ungureanu Date: Tue, 8 Mar 2016 22:43:14 +0200 Subject: [PATCH] MDEV-505: feature request: add \H option for mysql client prompt Introduce `\H` option which behaves mostly like `\h`. The only exception is when the client connects to the server hosted on localhost. In this case, the hostname will be used instead. --- client/mysql.cc | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/client/mysql.cc b/client/mysql.cc index 9c6320fe10a..f08a33207f7 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -5112,17 +5112,29 @@ static const char *construct_prompt() processed_prompt.append("unknown"); break; case 'h': + case 'H': { - const char *prompt; - prompt= connected ? mysql_get_host_info(&mysql) : "not_connected"; - if (strstr(prompt, "Localhost")) - processed_prompt.append("localhost"); - else - { - const char *end=strcend(prompt,' '); - processed_prompt.append(prompt, (uint) (end-prompt)); - } - break; + const char *prompt; + prompt= connected ? mysql_get_host_info(&mysql) : "not_connected"; + if (strstr(prompt, "Localhost")) + { + if (*c == 'h') + processed_prompt.append("localhost"); + else + { + char hostname[HOST_NAME_MAX]; + if (gethostname(hostname, sizeof(hostname)) == 0) + processed_prompt.append(hostname); + else + processed_prompt.append("gethostname(2) failed"); + } + } + else + { + const char *end=strcend(prompt,' '); + processed_prompt.append(prompt, (uint) (end-prompt)); + } + break; } case 'p': {