Re: [PATCH] Add tab-complete for backslash commands - Mailing list pgsql-hackers

From ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Subject Re: [PATCH] Add tab-complete for backslash commands
Date
Msg-id 87r1f4g86t.fsf@wibble.ilmari.org
Whole thread Raw
In response to [PATCH] Add tab-complete for backslash commands  ("tanghy.fnst@fujitsu.com" <tanghy.fnst@fujitsu.com>)
Responses RE: [PATCH] Add tab-complete for backslash commands
List pgsql-hackers
Hi Tang,

"tanghy.fnst@fujitsu.com" <tanghy.fnst@fujitsu.com> writes:

> Hi
>
> Attached a patch to improve the tab completion for backslash commands.
> I think it’s common for some people(I'm one of them) to use full-name
> commands than abbreviation.  So it's more convenient if we can add the
> full-name backslash commands in the tab-complete.c.

Even though I usually use the short versions, I agree that having the
full names in tab the completion as well is a good idea.

> When modify tab-complete.c, I found \dS was added in the
> backslash_commands[], but I think maybe it should be removed just like
> other \x[S].
> So I removed it.
> Besides, I also added a little change in help.c.
> - exchange the positon of \des and \det according to alphabetical order
> - rename PATRN1/PATRN2 to ROLEPTRN/DBPTRN to make expression more comprehensible

These are also good changes.

> Any comment is welcome.
>
> Regards,
> Tang

> +        "\\r", "\\rset",

There's a typo here, that should be "\\reset".  Also, I noticed that for
\connect, the situation is the opposite: it has the full form but not
the short form (\c).

I've addressed both in the attached v2 patch.

- ilmari

From b8809f7ce81d6252712e8f115e4fb2edd551b7ea Mon Sep 17 00:00:00 2001
From: tanghy <tanghy.fnst@fujitsu.com>
Date: Sun, 8 Aug 2021 00:05:27 +0100
Subject: [PATCH v2] Add tab completion for more backslash commands

Also improve the --help output for some backslash commands
---
 src/bin/psql/help.c         |  4 ++--
 src/bin/psql/tab-complete.c | 22 +++++++++++-----------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/bin/psql/help.c b/src/bin/psql/help.c
index d3fda67edd..3f8af98e6b 100644
--- a/src/bin/psql/help.c
+++ b/src/bin/psql/help.c
@@ -236,8 +236,8 @@ slashUsage(unsigned short int pager)
     fprintf(output, _("  \\dD[S+] [PATTERN]      list domains\n"));
     fprintf(output, _("  \\ddp    [PATTERN]      list default privileges\n"));
     fprintf(output, _("  \\dE[S+] [PATTERN]      list foreign tables\n"));
-    fprintf(output, _("  \\det[+] [PATTERN]      list foreign tables\n"));
     fprintf(output, _("  \\des[+] [PATTERN]      list foreign servers\n"));
+    fprintf(output, _("  \\det[+] [PATTERN]      list foreign tables\n"));
     fprintf(output, _("  \\deu[+] [PATTERN]      list user mappings\n"));
     fprintf(output, _("  \\dew[+] [PATTERN]      list foreign-data wrappers\n"));
     fprintf(output, _("  \\df[anptw][S+] [FUNCPTRN [TYPEPTRN ...]]\n"
@@ -257,7 +257,7 @@ slashUsage(unsigned short int pager)
     fprintf(output, _("  \\dO[S+] [PATTERN]      list collations\n"));
     fprintf(output, _("  \\dp     [PATTERN]      list table, view, and sequence access privileges\n"));
     fprintf(output, _("  \\dP[itn+] [PATTERN]    list [only index/table] partitioned relations [n=nested]\n"));
-    fprintf(output, _("  \\drds [PATRN1 [PATRN2]] list per-database role settings\n"));
+    fprintf(output, _("  \\drds [ROLEPTRN [DBPTRN]] list per-database role settings\n"));
     fprintf(output, _("  \\dRp[+] [PATTERN]      list replication publications\n"));
     fprintf(output, _("  \\dRs[+] [PATTERN]      list replication subscriptions\n"));
     fprintf(output, _("  \\ds[S+] [PATTERN]      list sequences\n"));
diff --git a/src/bin/psql/tab-complete.c b/src/bin/psql/tab-complete.c
index 064892bade..59caafda89 100644
--- a/src/bin/psql/tab-complete.c
+++ b/src/bin/psql/tab-complete.c
@@ -1503,31 +1503,31 @@ psql_completion(const char *text, int start, int end)
     /* psql's backslash commands. */
     static const char *const backslash_commands[] = {
         "\\a",
-        "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy",
+        "\\c", "\\connect", "\\conninfo", "\\C", "\\cd", "\\copy",
         "\\copyright", "\\crosstabview",
         "\\d", "\\da", "\\dA", "\\dAc", "\\dAf", "\\dAo", "\\dAp",
         "\\db", "\\dc", "\\dC", "\\dd", "\\ddp", "\\dD",
         "\\des", "\\det", "\\deu", "\\dew", "\\dE", "\\df",
         "\\dF", "\\dFd", "\\dFp", "\\dFt", "\\dg", "\\di", "\\dl", "\\dL",
         "\\dm", "\\dn", "\\do", "\\dO", "\\dp", "\\dP", "\\dPi", "\\dPt",
-        "\\drds", "\\dRs", "\\dRp", "\\ds", "\\dS",
+        "\\drds", "\\dRs", "\\dRp", "\\ds",
         "\\dt", "\\dT", "\\dv", "\\du", "\\dx", "\\dX", "\\dy",
-        "\\e", "\\echo", "\\ef", "\\elif", "\\else", "\\encoding",
+        "\\e", "\\echo", "\\edit", "\\ef", "\\elif", "\\else", "\\encoding",
         "\\endif", "\\errverbose", "\\ev",
         "\\f",
         "\\g", "\\gdesc", "\\gexec", "\\gset", "\\gx",
-        "\\h", "\\help", "\\H",
-        "\\i", "\\if", "\\ir",
-        "\\l", "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink",
-        "\\o",
-        "\\p", "\\password", "\\prompt", "\\pset",
-        "\\q", "\\qecho",
-        "\\r",
+        "\\h", "\\help", "\\html", "\\H",
+        "\\i", "\\if", "\\ir", "\\include", "\\include_relative",
+        "\\l", "\\list", "\\lo_import", "\\lo_export", "\\lo_list", "\\lo_unlink",
+        "\\o", "\\out",
+        "\\p", "\\password", "\\print", "\\prompt", "\\pset",
+        "\\q", "\\qecho", "\\quit",
+        "\\r", "\\reset",
         "\\s", "\\set", "\\setenv", "\\sf", "\\sv",
         "\\t", "\\T", "\\timing",
         "\\unset",
         "\\x",
-        "\\w", "\\warn", "\\watch",
+        "\\w", "\\warn", "\\watch", "\\write",
         "\\z",
         "\\!", "\\?",
         NULL
-- 
2.30.2


pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: ECPG bug fix: DECALRE STATEMENT and DEALLOCATE, DESCRIBE
Next
From: ilmari@ilmari.org (Dagfinn Ilmari Mannsåker)
Date:
Subject: Re: perlcritic: prohibit map and grep in void conext