Skip to content

Commit eca0607

Browse files
udan11svoj
authored andcommitted
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.
1 parent f2afeb3 commit eca0607

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

client/mysql.cc

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5112,17 +5112,29 @@ static const char *construct_prompt()
51125112
processed_prompt.append("unknown");
51135113
break;
51145114
case 'h':
5115+
case 'H':
51155116
{
5116-
const char *prompt;
5117-
prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
5118-
if (strstr(prompt, "Localhost"))
5119-
processed_prompt.append("localhost");
5120-
else
5121-
{
5122-
const char *end=strcend(prompt,' ');
5123-
processed_prompt.append(prompt, (uint) (end-prompt));
5124-
}
5125-
break;
5117+
const char *prompt;
5118+
prompt= connected ? mysql_get_host_info(&mysql) : "not_connected";
5119+
if (strstr(prompt, "Localhost"))
5120+
{
5121+
if (*c == 'h')
5122+
processed_prompt.append("localhost");
5123+
else
5124+
{
5125+
char hostname[HOST_NAME_MAX];
5126+
if (gethostname(hostname, sizeof(hostname)) == 0)
5127+
processed_prompt.append(hostname);
5128+
else
5129+
processed_prompt.append("gethostname(2) failed");
5130+
}
5131+
}
5132+
else
5133+
{
5134+
const char *end=strcend(prompt,' ');
5135+
processed_prompt.append(prompt, (uint) (end-prompt));
5136+
}
5137+
break;
51265138
}
51275139
case 'p':
51285140
{

0 commit comments

Comments
 (0)