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
</listitem>
</varlistentry>
+ <varlistentry id="app-psql-variables-service">
+ <term><varname>SERVICE</varname></term>
+ <listitem>
+ <para>
+ The service name, if applicable.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry id="app-psql-variables-shell-error">
<term><varname>SHELL_ERROR</varname></term>
<listitem>
</listitem>
</varlistentry>
+ <varlistentry id="app-psql-prompting-s">
+ <term><literal>%s</literal></term>
+ <listitem><para>The name of the service.</para></listitem>
+ </varlistentry>
+
<varlistentry id="app-psql-prompting-slash">
<term><literal>%/</literal></term>
<listitem><para>The name of the current database.</para></listitem>
pset.sversion = PQserverVersion(pset.db);
SetVariable(pset.vars, "DBNAME", PQdb(pset.db));
+ SetVariable(pset.vars, "SERVICE", PQservice(pset.db));
SetVariable(pset.vars, "USER", PQuser(pset.db));
SetVariable(pset.vars, "HOST", PQhost(pset.db));
SetVariable(pset.vars, "PORT", PQport(pset.db));
UnsyncVariables(void)
{
SetVariable(pset.vars, "DBNAME", NULL);
+ SetVariable(pset.vars, "SERVICE", NULL);
SetVariable(pset.vars, "USER", NULL);
SetVariable(pset.vars, "HOST", NULL);
SetVariable(pset.vars, "PORT", NULL);
* %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
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)