From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Improve psql's tab completion for filenames.
Date: Thu, 23 Jan 2020 16:07:22 +0000
Message-ID: <E1iuf0s-0001Z5-06@gemulon.postgresql.org> (raw)
Improve psql's tab completion for filenames.
The Readline library contains a fair amount of knowledge about how to
tab-complete filenames, but it turns out that that doesn't work too well
unless we follow its expectation that we use its filename quoting hooks
to quote and de-quote filenames. We were trying to do such quote handling
within complete_from_files(), and that's still what we have to do if we're
using libedit, which lacks those hooks. But for Readline, it works a lot
better if we tell Readline that single-quote is a quoting character and
then provide hooks that know the details of the quoting rules for SQL
and psql meta-commands.
Hence, resurrect the quoting hook functions that existed in the original
version of tab-complete.c (and were disabled by commit f6689a328 because
they "didn't work so well yet"), and whack on them until they do seem to
work well.
Notably, this fixes bug #16059 from Steven Winfield, who pointed out
that the previous coding would strip quote marks from filenames in SQL
COPY commands, even though they're syntactically necessary there.
Now, we not only don't do that, but we'll add a quote mark when you
tab-complete, even if you didn't type one.
Getting this to work across a range of libedit versions (and, to a
lesser extent, libreadline versions) was depressingly difficult.
It will be interesting to see whether the new regression test cases
pass everywhere in the buildfarm.
Some future patch might try to handle quoted SQL identifiers with
similar explicit quoting/dequoting logic, but that's for another day.
Patch by me, reviewed by Peter Eisentraut.
Discussion: https://postgr.es/m/16059-8836946734c02b84@postgresql.org
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/cd69ec66c88633c09bc9a984a7f0930e09c7c96e
Modified Files
--------------
config/programs.m4 | 52 ++++++-
configure | 87 +++++++++++-
configure.in | 2 +-
src/bin/psql/stringutils.c | 6 +-
src/bin/psql/stringutils.h | 3 +-
src/bin/psql/t/010_tab_completion.pl | 74 ++++++++++
src/bin/psql/tab-complete.c | 259 +++++++++++++++++++++++++++++------
src/include/pg_config.h.in | 8 ++
src/tools/msvc/Solution.pm | 2 +
9 files changed, 438 insertions(+), 55 deletions(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Improve psql's tab completion for filenames.
In-Reply-To: <E1iuf0s-0001Z5-06@gemulon.postgresql.org>
References: <E1iuf0s-0001Z5-06@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox