SSL indicator in psql prompt
I like how browsers show a little lock in the address bar depending on
whether SSL is in use. This could be useful in psql as well. Here is a
prototype patch.
Example:
Put this in .psqlrc:
\set PROMPT1 '%s%/%R%# '
$ psql test
psql (9.6devel)
Type "help" for help.
🔒test=#
Without SSL:
🃏test=#
Comments?
Attachments:
0001-psql-Add-s-prompt-placeholder-for-SSL-status.patchapplication/x-patch; name=0001-psql-Add-s-prompt-placeholder-for-SSL-status.patchDownload
From b3a79d56507c61b6fa6efba6f97a37acf822d39f Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter_e@gmx.net>
Date: Fri, 1 Apr 2016 00:00:00 +0000
Subject: [PATCH] psql: Add %s prompt placeholder for SSL status
---
doc/src/sgml/ref/psql-ref.sgml | 9 +++++++++
src/bin/psql/prompt.c | 20 ++++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/doc/src/sgml/ref/psql-ref.sgml b/doc/src/sgml/ref/psql-ref.sgml
index 385cb59..b4044e2 100644
--- a/doc/src/sgml/ref/psql-ref.sgml
+++ b/doc/src/sgml/ref/psql-ref.sgml
@@ -3512,6 +3512,15 @@ <title id="APP-PSQL-prompting-title">Prompting</title>
</varlistentry>
<varlistentry>
+ <term><literal>%s</literal></term>
+ <listitem>
+ <para>
+ A character indicating whether SSL is in use.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
<term><literal>%</literal><replaceable class="parameter">digits</replaceable></term>
<listitem>
<para>
diff --git a/src/bin/psql/prompt.c b/src/bin/psql/prompt.c
index 647e871..3c25a2f 100644
--- a/src/bin/psql/prompt.c
+++ b/src/bin/psql/prompt.c
@@ -21,6 +21,7 @@
#include "input.h"
#include "prompt.h"
#include "settings.h"
+#include "mb/pg_wchar.h"
/*--------------------------
@@ -44,6 +45,7 @@
* or a ! if session is not connected to a database;
* in prompt2 -, *, ', or ";
* in prompt3 nothing
+ * %s - SSL mode
* %x - transaction status: empty, *, !, ? (unknown or no connection)
* %l - The line number inside the current statement, starting from 1.
* %? - the error code of the last query (not yet implemented)
@@ -218,6 +220,24 @@ get_prompt(promptStatus_t status)
}
break;
+ case 's':
+ if (pset.db && PQsslInUse(pset.db))
+ {
+ if (pset.encoding == PG_UTF8)
+ strlcpy(buf, "\xF0\x9F\x94\x92 ", sizeof(buf)); /* U+1F512 */
+ else
+ strlcpy(buf, "#", sizeof(buf));
+ }
+ else
+ {
+ if (pset.encoding == PG_UTF8)
+ strlcpy(buf, "\xF0\x9F\x83\x8F", sizeof(buf)); /* U+1F0CF */
+ else
+ strlcpy(buf, "_", sizeof(buf));
+
+ }
+ break;
+
case 'x':
if (!pset.db)
buf[0] = '?';
--
2.8.0
On Fri, Apr 1, 2016 at 2:52 PM, Peter Eisentraut <peter_e@gmx.net> wrote:
I like how browsers show a little lock in the address bar depending on
whether SSL is in use. This could be useful in psql as well. Here is a
prototype patch.Example:
Put this in .psqlrc:
\set PROMPT1 '%s%/%R%# '
$ psql test
psql (9.6devel)
Type "help" for help.🔒test=#
Without SSL:
🃏test=#
Comments?
Sounds reasonable. What is the meaning of the latter symbol?
--
Alex
Peter Eisentraut <peter_e@gmx.net> writes:
I like how browsers show a little lock in the address bar depending on
whether SSL is in use. This could be useful in psql as well. Here is a
prototype patch.
Comments?
-1 on the hard-coded UTF8, even with the encoding check (which I don't
think is terribly trustworthy). How about defining it in a way that
lets/makes the user provide the character(s) to print?
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Fri, Apr 1, 2016 at 10:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Peter Eisentraut <peter_e@gmx.net> writes:
I like how browsers show a little lock in the address bar depending on
whether SSL is in use. This could be useful in psql as well. Here is a
prototype patch.
Comments?-1 on the hard-coded UTF8, even with the encoding check (which I don't
think is terribly trustworthy). How about defining it in a way that
lets/makes the user provide the character(s) to print?
I think you have been trolled. Note the date.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Apr 4, 2016 17:54, "Robert Haas" <robertmhaas@gmail.com> wrote:
On Fri, Apr 1, 2016 at 10:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Peter Eisentraut <peter_e@gmx.net> writes:
I like how browsers show a little lock in the address bar depending on
whether SSL is in use. This could be useful in psql as well. Here is
a
prototype patch.
Comments?-1 on the hard-coded UTF8, even with the encoding check (which I don't
think is terribly trustworthy). How about defining it in a way that
lets/makes the user provide the character(s) to print?I think you have been trolled. Note the date.
Are you trying to say that this feature is in your opinion useless?
Even if that's an April Fools patch, I don't thiy it is entirely out of
scope. :-)
--
Alex
On Mon, Apr 4, 2016 at 12:07 PM, Shulgin, Oleksandr
<oleksandr.shulgin@zalando.de> wrote:
On Apr 4, 2016 17:54, "Robert Haas" <robertmhaas@gmail.com> wrote:
On Fri, Apr 1, 2016 at 10:15 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Peter Eisentraut <peter_e@gmx.net> writes:
I like how browsers show a little lock in the address bar depending on
whether SSL is in use. This could be useful in psql as well. Here is
a
prototype patch.
Comments?-1 on the hard-coded UTF8, even with the encoding check (which I don't
think is terribly trustworthy). How about defining it in a way that
lets/makes the user provide the character(s) to print?I think you have been trolled. Note the date.
Are you trying to say that this feature is in your opinion useless?
Well, what I was trying to say is that I don't think the proposal was
100% serious. However, I also don't think it's particularly useful.
I am not a big fan of cluttering up the psql command line with random
Unicode glyphs. It's easy enough to find out whether you've got an
SSL connection if you want to, with \conninfo. I don't think it needs
to be part of every prompt.
YMMV, of course.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers