Skip to content

Commit c63583f

Browse files
authored
Merge pull request #3170 from mneedham/prompt-kb
Rewriting the prompt KB
2 parents ea0205e + e69dce2 commit c63583f

File tree

10 files changed

+130
-50
lines changed

10 files changed

+130
-50
lines changed
Lines changed: 130 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,160 @@
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
5-
tags: ['Settings']
5+
tags: ['Settings', 'Native Clients and Interfaces']
66
keywords: ['ClickHouse Client', 'Change Prompt']
77
---
88

99
{frontMatter.description}
1010
{/* truncate */}
1111

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

14-
Want to change your ClickHouse Client prompt? Read on.
13+
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.
14+
This article explains how to change the prompt to whatever you want.
1515

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

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.
18+
![](./images/change-the-prompt-in-clickhouse-client/0_prompt.png)
1919

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

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

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

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

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

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

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

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

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

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-
```
125+
![](./images/change-the-prompt-in-clickhouse-client/6_prompt.png)
53126

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:
127+
And here's a YAML version:
55128

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-
```
129+
```yaml
130+
connections_credentials:
131+
connection:
132+
- name: prod
133+
hostname: 127.0.0.1
134+
port: 9000
135+
secure: 0
136+
user: default
137+
prompt: "\e[35m[PRODUCTION]\e[0m {user}@{host}"
138+
- name: dev
139+
hostname: 127.0.0.1
140+
port: 9000
141+
secure: 0
142+
user: default
143+
prompt: "\e[34m[DEVELOPMENT]\e[0m {user}@{host}"
144+
```
64145
65-
1. Save the `custom-config.xml` file.
66-
1. Start the Clickhouse server if it isn't already running:
146+
With the `dev` connnection:
67147

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

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

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

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

80-
![](./images/change-the-prompt-in-clickhouse-client/custom-prompt-full-command-example.png)
160+
![](./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)