ksh completion for [, :, $

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

ksh completion for [, :, $

Alexander Polakov-2
Hi there,

I sent this diff to bugs@ some time ago but haven't got any replies.
Probably tech@ is a better place for it.

The problem is known as bz#6006/user.

The fix is taken from mksh (rev.1.4 for [ and rev.1.184 for others).
It adds quoting character (QCHAR) when [, $, ` are prepended by \ to make
them be interpreted literally (like if they were enclosed in ' ').
It also adds : to the list of escaped characters.
Original commit message:

revision 1.184
date: 2009-10-30 00:57:36 +0000;  author: tg;  state: Exp;  lines: +10 -8;  commitid: 1004AEA39BD3F10ECFA;
make tab completing filenames with ':' '=' '$' '`' work as well as
others (colon and equals sign need to be simply escaped, while dollar
sign and accent gravis need double escaping like opening square brak-
ket did back then); add = to C_QUOTE to simplify (doesn't break any-
thing) and sort these strings asciibetically while here


Index: bin/ksh/edit.c
===================================================================
RCS file: /cvs/src/bin/ksh/edit.c,v
retrieving revision 1.34
diff -u -r1.34 edit.c
--- bin/ksh/edit.c 20 May 2010 01:13:07 -0000 1.34
+++ bin/ksh/edit.c 4 Feb 2011 17:58:48 -0000
@@ -365,6 +365,11 @@
  continue;
  }
 
+ /* specially escape escaped [ or $ or ` for globbing */
+ if (escaping && (toglob[i] == '[' ||
+    toglob[i] == '$' || toglob[i] == '`'))
+ toglob[idx++] = QCHAR;
+
  toglob[idx] = toglob[i];
  idx++;
  if (escaping) escaping = 0;
@@ -378,7 +383,7 @@
  s = pushs(SWSTR, ATEMP);
  s->start = s->str = toglob;
  source = s;
- if (yylex(ONEWORD) != LWORD) {
+ if (yylex(ONEWORD|LQCHAR) != LWORD) {
  source = sold;
  internal_errorf(0, "fileglob: substitute error");
  return 0;
@@ -821,7 +826,7 @@
  int rval = 0;
 
  for (add = 0, wlen = len; wlen - add > 0; add++) {
- if (strchr("\"#$&'()*;<=>?[\\]`{|}", s[add]) ||
+ if (strchr("\"#$&'()*:;<=>?[\\]`{|}", s[add]) ||
     strchr(ifs, s[add])) {
  if (putbuf_func(s, add) != 0) {
  rval = -1;
Index: bin/ksh/lex.c
===================================================================
RCS file: /cvs/src/bin/ksh/lex.c,v
retrieving revision 1.44
diff -u -r1.44 lex.c
--- bin/ksh/lex.c 3 Jul 2008 17:52:08 -0000 1.44
+++ bin/ksh/lex.c 4 Feb 2011 17:58:48 -0000
@@ -411,6 +411,13 @@
  }
  }
  break;
+ case QCHAR:
+ if (cf & LQCHAR) {
+ *wp++ = QCHAR;
+ *wp++ = getsc();
+ break;
+ }
+ /* fallthrough */
  default:
  *wp++ = CHAR, *wp++ = c;
  }
Index: bin/ksh/lex.h
===================================================================
RCS file: /cvs/src/bin/ksh/lex.h,v
retrieving revision 1.11
diff -u -r1.11 lex.h
--- bin/ksh/lex.h 29 May 2006 18:22:24 -0000 1.11
+++ bin/ksh/lex.h 4 Feb 2011 17:58:48 -0000
@@ -113,6 +113,7 @@
 #define CMDWORD BIT(8) /* parsing simple command (alias related) */
 #define HEREDELIM BIT(9) /* parsing <<,<<- delimiter */
 #define HEREDOC BIT(10) /* parsing heredoc */
+#define LQCHAR BIT(11) /* source string contains QCHAR */
 
 #define HERES 10 /* max << in line */
 

--
Alexander Polakov | plhk.ru

Reply | Threaded
Open this post in threaded view
|

Re: ksh completion for [, :, $

Nick Guenther
On Fri, Feb 4, 2011 at 1:42 PM, Alexander Polakov <[hidden email]> wrote:

> Hi there,
>
> I sent this diff to bugs@ some time ago but haven't got any replies.
> Probably tech@ is a better place for it.
>
> The problem is known as bz#6006/user.
>
> The fix is taken from mksh (rev.1.4 for [ and rev.1.184 for others).
> It adds quoting character (QCHAR) when [, $, ` are prepended by \ to make
> them be interpreted literally (like if they were enclosed in ' ').
> It also adds : to the list of escaped characters.
> Original commit message:

This. PLEASE.

-Nick