Skip to content

Commit 01851a6

Browse files
committed
Rewriting the prompt KB
1 parent 0d058a3 commit 01851a6

File tree

10 files changed

+129
-50
lines changed

10 files changed

+129
-50
lines changed
Lines changed: 129 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,159 @@
11
---
22
title: Change the prompt in clickhouse-client
3-
description: "This article explains how to change the prompt in your Clickhouse client terminal window from :) to whatever you want."
3+
description: "This article explains how to change the prompt in your Clickhouse client and clickhouse-local terminal window from :) to a prefix followed by :)"
44
date: 2023-11-16
55
tags: ['Settings']
66
keywords: ['ClickHouse Client', 'Change Prompt']
77
---
88

99
{frontMatter.description}
10-
{/* truncate */}
1110

12-
## Change the prompt in `clickhouse client`
1311

14-
Want to change your ClickHouse Client prompt? Read on.
12+
If you don't like how `clickhouse client` and clickhouse-local display the prompt in your terminal window, it is possible to change it to add a prefix.
13+
This article explains how to change the prompt to whatever you want.
1514

16-
## Background
15+
The default prompt is your local computer name followed by `:) `:
1716

18-
If you don't like how `clickhouse client` displays the prompt in your terminal window, it's possible to change it by creating a single XML file. This article explains how to change the prompt to whatever you want.
17+
![](./images/change-the-prompt-in-clickhouse-client/0_prompt.png)
1918

20-
The default prompt is your local computer name followed by `:) `:
19+
The following are variables that you can use in a prompt: `{user}`, `{host}`
20+
21+
There are several ways to update the prompt and we'll go through them each.
22+
23+
24+
## --prompt flag
25+
26+
The first way to change the flag is using the `--prompt`:
27+
28+
```bash
29+
clickhouse --prompt 👉
30+
```
31+
32+
This will add the finger emoji before the smiley face:
33+
34+
![](./images/change-the-prompt-in-clickhouse-client/1_prompt.png)
35+
36+
## Config file - top level
37+
38+
Alternatively, you can provide a prompt prefix in a `config.xml` file:
39+
40+
```xml
41+
<config>
42+
<prompt>👉 </prompt>
43+
</config>
44+
```
45+
46+
```
47+
clickhouse
48+
```
49+
50+
51+
![](./images/change-the-prompt-in-clickhouse-client/2_prompt.png)
52+
53+
We can use a config file with any name we like and pass it in using the `-C` flag:
54+
55+
```xml
56+
<config>
57+
<prompt>🎄 </prompt>
58+
</config>
59+
```
60+
61+
62+
```
63+
clickhouse -C christmas.xml
64+
```
65+
66+
![](./images/change-the-prompt-in-clickhouse-client/3_prompt.png)
67+
68+
Prefer your config files to be in YAML?
69+
That works too:
70+
71+
```yaml
72+
prompt: 🟡
73+
```
74+
75+
76+
```bash
77+
clickhouse -C christmas.yaml
78+
```
79+
80+
![](./images/change-the-prompt-in-clickhouse-client/4_prompt.png)
2181

22-
![](./images/change-the-prompt-in-clickhouse-client/default-prompt-example.png)
82+
## Config file - connections_credentials
2383

24-
However, you can edit the prompt to be whatever you want:
84+
Alternatively, you can specify a prompt per connection credentials.
85+
This only makes sense when using clickhouse-client.
2586

26-
![](./images/change-the-prompt-in-clickhouse-client/custom-prompt-example.png)
87+
```xml
88+
<config>
89+
<connections_credentials>
90+
<connection>
91+
<name>prod</name>
92+
<hostname>127.0.0.1</hostname>
93+
<port>9000</port>
94+
<secure>0</secure>
95+
<user>default</user>
96+
<prompt>\e[31m[PRODUCTION]\e[0m {user}@prod</prompt>
97+
</connection>
98+
<connection>
99+
<name>dev</name>
100+
<hostname>127.0.0.1</hostname>
101+
<port>9000</port>
102+
<secure>0</secure>
103+
<user>default</user>
104+
<prompt>\e[32m[DEVELOPMENT]\e[0m {user}@dev</prompt>
105+
</connection>
106+
</connections_credentials>
107+
</config>
108+
```
27109

28-
## Steps
110+
We can then try to connect with the `dev` connection:
29111

30-
To edit the prompt, follow these steps:
112+
```bash
113+
clickhouse client -C connections.xml --connection dev
114+
```
31115

32-
1. Find where you `clickhouse` executable is stored, and create a file call `custom-config.xml` in the same directory:
116+
![](./images/change-the-prompt-in-clickhouse-client/5_prompt.png)
33117

34-
```plaintext
35-
./
36-
├── clickhouse
37-
├── custom-config.xml
38-
...
39-
├── user_scripts
40-
└── uuid
41-
```
118+
Or the `prod` one:
42119

43-
1. Inside `custom-config.xml` paste the following code:
120+
```bash
121+
clickhouse client -C connections.xml --connection prod
122+
```
44123

45-
```xml
46-
<?xml version="1.0" ?>
47-
<clickhouse>
48-
<prompt_by_server_display_name>
49-
<default>CUSTOM_PROMPT_HERE</default>
50-
</prompt_by_server_display_name>
51-
</clickhouse>
52-
```
124+
![](./images/change-the-prompt-in-clickhouse-client/6_prompt.png)
53125

54-
1. Replace `CUSTOM_PROMPT_HERE` with whatever you want your prompt to say. You must keep the prompt to a single line between the opening and closing `<default>` tags:
126+
And here's a YAML version:
55127

56-
```shell
57-
<?xml version="1.0" ?>
58-
<clickhouse>
59-
<prompt_by_server_display_name>
60-
<default>local_clickhouse_client $> </default>
61-
</prompt_by_server_display_name>
62-
</clickhouse>
63-
```
128+
```yaml
129+
connections_credentials:
130+
connection:
131+
- name: prod
132+
hostname: 127.0.0.1
133+
port: 9000
134+
secure: 0
135+
user: default
136+
prompt: "\e[35m[PRODUCTION]\e[0m {user}@{host}"
137+
- name: dev
138+
hostname: 127.0.0.1
139+
port: 9000
140+
secure: 0
141+
user: default
142+
prompt: "\e[34m[DEVELOPMENT]\e[0m {user}@{host}"
143+
```
64144
65-
1. Save the `custom-config.xml` file.
66-
1. Start the Clickhouse server if it isn't already running:
145+
With the `dev` connnection:
67146

68-
```shell
69-
./clickhouse server
70-
```
147+
```bash
148+
clickhouse client -C connections.yaml --connection dev
149+
```
71150

72-
1. In a new terminal window, start the Clickhouse client with the `--config-file=custom-config.xml` argument:
151+
![](./images/change-the-prompt-in-clickhouse-client/7_prompt.png)
73152

74-
```shell
75-
./clickhouse client --config-file="custom-config.xml"
76-
```
153+
And now `prod`:
77154

78-
1. The Clickhouse client should open and display your custom prompt:
155+
```bash
156+
clickhouse client -C connections.yaml --connection prod
157+
```
79158

80-
![](./images/change-the-prompt-in-clickhouse-client/custom-prompt-full-command-example.png)
159+
![](./images/change-the-prompt-in-clickhouse-client/8_prompt.png)
50 KB
Loading
61.3 KB
Loading
107 KB
Loading
117 KB
Loading
87.4 KB
Loading
19.5 KB
Loading
20.7 KB
Loading
23.5 KB
Loading
24.2 KB
Loading

0 commit comments

Comments
 (0)