MySQL Shell 8.0.13 Prompt: Now with New Line Support
I have already blogged a couple of times about the MySQL Shell prompt. In the first blog, I wrote about how in general to configure it, and in the second blog, I showed how to install the necessary fonts to use the prompt with the Awesome and Powerline fonts.
In this blog, I will show a new feature of MySQL Shell 8.0.13 which adds support to have a line break in the prompt and still get multi line statements align correctly. I will first discuss why you may want to use the new feature, then go through the new templates using this feature, and finally show my current favourite prompt.
Why Use a New Line in the Prompt?
You may ask why this feature is needed? The MySQL Shell prompt has support for showing a lot of information. While this is very nice, it also makes the prompt rather long. When you then have your query/statement, it requires a fair amount of real estate. Adding a new line in the prompt allows you to keep all the great information while still limiting the overall with of the prompt. The following figure shows a comparison of the single line prompt with a multi line prompt:
Note that in the example, the multi line prompt includes the MySQL Server version which is not included in the single line prompt. It can of course be debated which of the two versions is preferable, but that is the beauty of MySQL Shell: you can choose the prompt that you prefer.
Now, lets look at the new templates in MySQL Shell 8.0.13.
New Prompt Templates with Line Breaks
There are three new prompt templates in the MySQL Shell installation. The prompt templates are located in /usr/share/mysqlsh/prompt/
on Linux and C:\Program Files\MySQL\MySQL Shell 8.0\share\mysqlsh\prompt
on Microsoft Windows. You may also want to review the blog Configuring the MySQL Shell Prompt for more about the prompt templates. The three new prompt templates are:
- prompt_dbl_256.json: The prompt uses 256 indexed colours. This is a two line version of the default prompt both on Oracle Linux 7 and Microsoft Windows 10.
- prompt_dbl_256pl.json: Similar to the prompt_dbl_256.json prompt but using the Powerline font.
- prompt_dbl_256pl+aw.json: Additionally adding the Awesome font symbols.
If you compare the prompt_dbl_256.json
template with the default prompt_256.json
template, the difference is:
So a new line is created using the "break": true
syntax. That's it. The other change in the screen shot is just to make the second line of the prompt be slightly indented.
This is great – if you want a new line before the end of the prompt, you can just use one of the new templates. However, personally I prefer to have my prompt slightly different.
My Favourite Prompt
My favourite prompt uses both the Awesome and Powerline fonts as well as adding a new line. I prefer to have the line break just before the language mode (the templates have the break after the mode). Additionally, I add the MySQL Server version (the value of the version
system variable), and I use the Powerline separator on each new line.
The complete prompt definition is:
{
"desc" : "256/24bit color terminal theme with MySQL prefix, default schema, host:port, ssl, + indicator for X protocol, MySQL version, new line, active mode. Requires Powerline patched font with awesome symbols (e.g. awesome-terminal-fonts)",
"classes" : {
"SQL" : {
"fg" : "15",
"bg" : "166"
},
"JS" : {
"fg" : "0",
"bg" : "221"
},
"Py" : {
"fg" : "15",
"bg" : "25"
},
"schema" : {
"text": "\ue894 %schema%"
},
"noschema" : {
"text": ""
},
"disconnected": {
},
"hostx" : {
"text": "\ue895 %transport%+"
},
"hostc" : {
"text": "\ue895 %transport%"
},
"SSLhostx" : {
"text": "\ue895 %transport%+ \ue0a2"
},
"SSLhostc" : {
"text": "\ue895 %transport% \ue0a2"
},
"production" : {
"text": " PRODUCTION ",
"bg": "red",
"fg": "white"
},
"version": {
"text": " %sysvar:version% ",
"bg": "blue",
"fg": 15
}
},
"variables" : {
"is_production": {
"match" : {
"pattern": "*;%host%;*",
"value": ";%env:PRODUCTION_SERVERS%;"
},
"if_true" : "production",
"if_false" : ""
},
"transport" : {
"match" : {
"pattern": "%socket%",
"value": ""
},
"if_true": "%host%:%port%",
"if_false": "localhost"
}
},
"symbols" : {
"separator" : "\ue0b0",
"separator2" : "\ue0b1",
"ellipsis" : "\u2026"
},
"prompt" : {
"text" : "\ue0b0 ",
"cont_text" : " \ue0b0 ",
"bg": "0"
},
"segments": [
{
"classes": ["disconnected%host%", "%is_production%"]
},
{
"text": " My",
"bg": 254,
"fg": 23
},
{
"separator": "",
"text": "SQL ",
"bg": 254,
"fg": 166
},
{
"classes": ["disconnected%host%", "%ssl%host%session%"],
"shrink": "truncate_on_dot",
"bg": 237,
"fg": 15,
"weight": 10,
"padding" : 1
},
{
"classes": ["disconnected%host%", "version"]
},
{
"classes": ["noschema%schema%", "schema"],
"bg": 242,
"fg": 15,
"shrink": "ellipsize",
"weight": -1,
"padding" : 1
},
{
"text": " ",
"bg": 0
},
{
"break": true
},
{
"classes": ["%Mode%"],
"text": "%Mode%",
"padding" : 1
},
]
}
Examples of the resulting prompt are:
Enjoy.
0 Comments on “MySQL Shell 8.0.13 Prompt: Now with New Line Support”