|
1 | 1 | ---
|
2 | 2 | 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 :)" |
4 | 4 | date: 2023-11-16
|
5 |
| -tags: ['Settings'] |
| 5 | +tags: ['Settings', 'Native Clients and Interfaces'] |
6 | 6 | keywords: ['ClickHouse Client', 'Change Prompt']
|
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | {frontMatter.description}
|
10 | 10 | {/* truncate */}
|
11 | 11 |
|
12 |
| -## Change the prompt in `clickhouse client` |
13 | 12 |
|
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. |
15 | 15 |
|
16 |
| -## Background |
| 16 | +The default prompt is your local computer name followed by `:) `: |
17 | 17 |
|
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 | + |
19 | 19 |
|
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 | + |
| 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 | + |
| 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 | + |
| 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 | + |
21 | 82 |
|
22 |
| - |
| 83 | +## Config file - connections_credentials |
23 | 84 |
|
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. |
25 | 87 |
|
26 |
| - |
| 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 | +``` |
27 | 110 |
|
28 |
| -## Steps |
| 111 | +We can then try to connect with the `dev` connection: |
29 | 112 |
|
30 |
| -To edit the prompt, follow these steps: |
| 113 | +```bash |
| 114 | +clickhouse client -C connections.xml --connection dev |
| 115 | +``` |
31 | 116 |
|
32 |
| -1. Find where you `clickhouse` executable is stored, and create a file call `custom-config.xml` in the same directory: |
| 117 | + |
33 | 118 |
|
34 |
| - ```plaintext |
35 |
| - ./ |
36 |
| - ├── clickhouse |
37 |
| - ├── custom-config.xml |
38 |
| - ... |
39 |
| - ├── user_scripts |
40 |
| - └── uuid |
41 |
| - ``` |
| 119 | +Or the `prod` one: |
42 | 120 |
|
43 |
| -1. Inside `custom-config.xml` paste the following code: |
| 121 | +```bash |
| 122 | +clickhouse client -C connections.xml --connection prod |
| 123 | +``` |
44 | 124 |
|
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 | + |
53 | 126 |
|
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: |
55 | 128 |
|
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 | +``` |
64 | 145 |
|
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: |
67 | 147 |
|
68 |
| - ```shell |
69 |
| - ./clickhouse server |
70 |
| - ``` |
| 148 | +```bash |
| 149 | +clickhouse client -C connections.yaml --connection dev |
| 150 | +``` |
71 | 151 |
|
72 |
| -1. In a new terminal window, start the Clickhouse client with the `--config-file=custom-config.xml` argument: |
| 152 | + |
73 | 153 |
|
74 |
| - ```shell |
75 |
| - ./clickhouse client --config-file="custom-config.xml" |
76 |
| - ``` |
| 154 | +And now `prod`: |
77 | 155 |
|
78 |
| -1. The Clickhouse client should open and display your custom prompt: |
| 156 | +```bash |
| 157 | +clickhouse client -C connections.yaml --connection prod |
| 158 | +``` |
79 | 159 |
|
80 |
| -  |
| 160 | + |
0 commit comments