Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 130 additions & 50 deletions knowledgebase/change-the-prompt-in-clickhouse-client.mdx
Original file line number Diff line number Diff line change
@@ -1,80 +1,160 @@
---
title: Change the prompt in clickhouse-client
description: "This article explains how to change the prompt in your Clickhouse client terminal window from :) to whatever you want."
description: "This article explains how to change the prompt in your Clickhouse client and clickhouse-local terminal window from :) to a prefix followed by :)"
date: 2023-11-16
tags: ['Settings']
tags: ['Settings', 'Native Clients and Interfaces']
keywords: ['ClickHouse Client', 'Change Prompt']
---

{frontMatter.description}
{/* truncate */}

## Change the prompt in `clickhouse client`

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

## Background
The default prompt is your local computer name followed by `:) `:

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

The default prompt is your local computer name followed by `:) `:
The following are variables that you can use in a prompt: `{user}`, `{host}`

There are several ways to update the prompt and we'll go through them each.


## --prompt flag

The first way to change the flag is using the `--prompt`:

```bash
clickhouse --prompt 👉
```

This will add the finger emoji before the smiley face:

![](./images/change-the-prompt-in-clickhouse-client/1_prompt.png)

## Config file - top level

Alternatively, you can provide a prompt prefix in a `config.xml` file:

```xml
<config>
<prompt>👉 </prompt>
</config>
```

```
clickhouse
```


![](./images/change-the-prompt-in-clickhouse-client/2_prompt.png)

We can use a config file with any name we like and pass it in using the `-C` flag:

```xml
<config>
<prompt>🎄 </prompt>
</config>
```


```
clickhouse -C christmas.xml
```

![](./images/change-the-prompt-in-clickhouse-client/3_prompt.png)

Prefer your config files to be in YAML?
That works too:

```yaml
prompt: 🟡
```


```bash
clickhouse -C christmas.yaml
```

![](./images/change-the-prompt-in-clickhouse-client/4_prompt.png)

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

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

![](./images/change-the-prompt-in-clickhouse-client/custom-prompt-example.png)
```xml
<config>
<connections_credentials>
<connection>
<name>prod</name>
<hostname>127.0.0.1</hostname>
<port>9000</port>
<secure>0</secure>
<user>default</user>
<prompt>\e[31m[PRODUCTION]\e[0m {user}@prod</prompt>
</connection>
<connection>
<name>dev</name>
<hostname>127.0.0.1</hostname>
<port>9000</port>
<secure>0</secure>
<user>default</user>
<prompt>\e[32m[DEVELOPMENT]\e[0m {user}@dev</prompt>
</connection>
</connections_credentials>
</config>
```

## Steps
We can then try to connect with the `dev` connection:

To edit the prompt, follow these steps:
```bash
clickhouse client -C connections.xml --connection dev
```

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

```plaintext
./
├── clickhouse
├── custom-config.xml
...
├── user_scripts
└── uuid
```
Or the `prod` one:

1. Inside `custom-config.xml` paste the following code:
```bash
clickhouse client -C connections.xml --connection prod
```

```xml
<?xml version="1.0" ?>
<clickhouse>
<prompt_by_server_display_name>
<default>CUSTOM_PROMPT_HERE</default>
</prompt_by_server_display_name>
</clickhouse>
```
![](./images/change-the-prompt-in-clickhouse-client/6_prompt.png)

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

```shell
<?xml version="1.0" ?>
<clickhouse>
<prompt_by_server_display_name>
<default>local_clickhouse_client $> </default>
</prompt_by_server_display_name>
</clickhouse>
```
```yaml
connections_credentials:
connection:
- name: prod
hostname: 127.0.0.1
port: 9000
secure: 0
user: default
prompt: "\e[35m[PRODUCTION]\e[0m {user}@{host}"
- name: dev
hostname: 127.0.0.1
port: 9000
secure: 0
user: default
prompt: "\e[34m[DEVELOPMENT]\e[0m {user}@{host}"
```

1. Save the `custom-config.xml` file.
1. Start the Clickhouse server if it isn't already running:
With the `dev` connnection:

```shell
./clickhouse server
```
```bash
clickhouse client -C connections.yaml --connection dev
```

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

```shell
./clickhouse client --config-file="custom-config.xml"
```
And now `prod`:

1. The Clickhouse client should open and display your custom prompt:
```bash
clickhouse client -C connections.yaml --connection prod
```

![](./images/change-the-prompt-in-clickhouse-client/custom-prompt-full-command-example.png)
![](./images/change-the-prompt-in-clickhouse-client/8_prompt.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.