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
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Features
---------
* Allow shorter timeout lengths after pressing Esc, for vi-mode.
* Let tab and control-space behaviors be configurable.
* Add short hostname prompt format string.


1.60.0 (2026/03/05)
Expand Down
4 changes: 4 additions & 0 deletions mycli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,9 +1574,13 @@ def get_prompt(self, string: str, _render_counter: int) -> str:
prompt_host = sqlexecute.host
else:
prompt_host = "localhost"
short_prompt_host, _, _ = prompt_host.partition('.')
if re.match(r'^[\d\.]+$', short_prompt_host):
short_prompt_host = prompt_host
now = datetime.now()
string = string.replace("\\u", sqlexecute.user or "(none)")
string = string.replace("\\h", prompt_host or "(none)")
string = string.replace("\\H", short_prompt_host or "(none)")
string = string.replace("\\d", sqlexecute.dbname or "(none)")
string = string.replace("\\t", sqlexecute.server_info.species.name)
string = string.replace("\\n", "\n")
Expand Down
1 change: 1 addition & 0 deletions mycli/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ wider_completion_menu = False
# * \P - AM/PM
# * \d - selected database/schema
# * \h - hostname of the server
# * \H - shortened hostname of the server
# * \p - connection port
# * \j - connection socket basename
# * \J - full connection socket path
Expand Down
1 change: 1 addition & 0 deletions test/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ wider_completion_menu = False
# * \P - AM/PM
# * \d - selected database/schema
# * \h - hostname of the server
# * \H - shortened hostname of the server
# * \p - connection port
# * \j - connection socket basename
# * \J - full connection socket path
Expand Down
15 changes: 15 additions & 0 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,21 @@ def test_prompt_socket_overrides_port(executor):
assert prompt == "MySQL root@localhost:mysqld.sock mysql> "


@dbtest
def test_prompt_socket_short_host(executor):
mycli = MyCli()
mycli.prompt_format = "\\t \\u@\\H:\\k \\d> "
mycli.sqlexecute = SQLExecute
mycli.sqlexecute.server_info = ServerInfo.from_version_string("8.0.44-0ubuntu0.24.04.1")
mycli.sqlexecute.host = 'localhost.localdomain'
mycli.sqlexecute.socket = None
mycli.sqlexecute.user = "root"
mycli.sqlexecute.dbname = "mysql"
mycli.sqlexecute.port = "3306"
prompt = mycli.get_prompt(mycli.prompt_format, 0)
assert prompt == "MySQL root@localhost:3306 mysql> "


@dbtest
def test_enable_show_warnings(executor):
mycli = MyCli()
Expand Down
Loading