From 477728b5d6fa16461b81cd22b0568fec1eab97ac Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Wed, 18 Dec 2024 15:16:12 +0900 Subject: psql: Add more information about service name This commit adds support for the following items in psql, able to show a service name, when available: - Variable SERVICE. - Substitution %s in PROMPT{1,2,3}. This relies on 4b99fed7541e, that has made the service name available in PGconn for libpq. Author: Michael Banck Reviewed-by: Greg Sabino Mullane Discussion: https://postgr.es/m/6723c612.050a0220.1567f4.b94a@mx.google.com --- src/bin/psql/prompt.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/bin/psql/prompt.c') diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c index 0d99d00ac92..ea880bcacbe 100644 --- a/src/bin/psql/prompt.c +++ b/src/bin/psql/prompt.c @@ -33,6 +33,7 @@ * %p - backend pid * %> - database server port number * %n - database user name + * %s - service * %/ - current database * %~ - like %/ but "~" when database name equals user name * %w - whitespace of the same width as the most recent output of PROMPT1 @@ -165,6 +166,11 @@ get_prompt(promptStatus_t status, ConditionalStack cstack) if (pset.db) strlcpy(buf, session_username(), sizeof(buf)); break; + /* service name */ + case 's': + if (pset.db && PQservice(pset.db)) + strlcpy(buf, PQservice(pset.db), sizeof(buf)); + break; /* backend pid */ case 'p': if (pset.db) -- cgit v1.2.3