Re: ksh completion
On Sun, Jun 19, 2011 at 15:26:26 -0400, STeve Andre' wrote: I hope not. I've seen this as well. I want to test this, seeing as how I just bumped into this. Can you post the last patch for this? Alexander has a whole bunch of excelent stuff for ksh in his repo. Seven patches IIRC, and they really improve the usability of ksh (including the command completing). Hope he'll repost them (or the URL for it) soon. Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
Re: ksh completion
On sze, maj 11, 2011 at 16:13:45 +0200, LEVAI Daniel wrote: On Tue, May 10, 2011 at 15:23:52 +0400, Alexander Polakov wrote: * LEVAI Daniel l...@ecentrum.hu [110510 14:33]: On Tue, May 10, 2011 at 12:28:06 +0200, LEVAI Daniel wrote: [...] Apperantly, adding ':' to ESCAPEDCHARS solves the problem. Do you think there is any sideeffect to this? No, I don't think so. Let's just add it and find out in practice. So far so good. I really like this patch. Thanks for it :) Is it acceptable in the tree? Is this really going down the sewers? Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
Re: ksh completion
On 06/19/11 14:38, LEVAI Daniel wrote: On sze, maj 11, 2011 at 16:13:45 +0200, LEVAI Daniel wrote: On Tue, May 10, 2011 at 15:23:52 +0400, Alexander Polakov wrote: * LEVAI Daniell...@ecentrum.hu [110510 14:33]: On Tue, May 10, 2011 at 12:28:06 +0200, LEVAI Daniel wrote: [...] Apperantly, adding ':' to ESCAPEDCHARS solves the problem. Do you think there is any sideeffect to this? No, I don't think so. Let's just add it and find out in practice. So far so good. I really like this patch. Thanks for it :) Is it acceptable in the tree? Is this really going down the sewers? Daniel I hope not. I've seen this as well. I want to test this, seeing as how I just bumped into this. Can you post the last patch for this? --STeve Andre'
Re: ksh completion
On Tue, May 10, 2011 at 15:23:52 +0400, Alexander Polakov wrote: * LEVAI Daniel l...@ecentrum.hu [110510 14:33]: On Tue, May 10, 2011 at 12:28:06 +0200, LEVAI Daniel wrote: On Tue, May 10, 2011 at 08:41:48 +0200, LEVAI Daniel wrote: On Mon, May 09, 2011 at 23:48:46 +0400, Alexander Polakov wrote: * Alexander Polakov polac...@gmail.com [110502 18:19]: Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? That diff was wrong, this one is likely less wrong. This is working fine for me. I've just found a usecase where it fails to complete a filename: $ touch 'aaa: bbb ccc' $ touch 'aaa: bbc ddd' $ ls -la aTAB $ ls -la aaa:\ bbTAB aaa: bbb ccc aaa: bbc ddd $ ls -la aaa:\ bbcTAB ^^^ nothing happens Apperantly, adding ':' to ESCAPEDCHARS solves the problem. Do you think there is any sideeffect to this? No, I don't think so. Let's just add it and find out in practice. So far so good. I really like this patch. Thanks for it :) Is it acceptable in the tree? Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
Re: ksh completion
On Tue, May 10, 2011 at 08:41:48 +0200, LEVAI Daniel wrote: On Mon, May 09, 2011 at 23:48:46 +0400, Alexander Polakov wrote: * Alexander Polakov polac...@gmail.com [110502 18:19]: Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? That diff was wrong, this one is likely less wrong. This is working fine for me. I've just found a usecase where it fails to complete a filename: $ touch 'aaa: bbb ccc' $ touch 'aaa: bbc ddd' $ ls -la aTAB $ ls -la aaa:\ bbTAB aaa: bbb ccc aaa: bbc ddd $ ls -la aaa:\ bbcTAB ^^^ nothing happens Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
Re: ksh completion
On Tue, May 10, 2011 at 12:28:06 +0200, LEVAI Daniel wrote: On Tue, May 10, 2011 at 08:41:48 +0200, LEVAI Daniel wrote: On Mon, May 09, 2011 at 23:48:46 +0400, Alexander Polakov wrote: * Alexander Polakov polac...@gmail.com [110502 18:19]: Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? That diff was wrong, this one is likely less wrong. This is working fine for me. I've just found a usecase where it fails to complete a filename: $ touch 'aaa: bbb ccc' $ touch 'aaa: bbc ddd' $ ls -la aTAB $ ls -la aaa:\ bbTAB aaa: bbb ccc aaa: bbc ddd $ ls -la aaa:\ bbcTAB ^^^ nothing happens Apperantly, adding ':' to ESCAPEDCHARS solves the problem. Do you think there is any sideeffect to this? Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
Re: ksh completion
* LEVAI Daniel l...@ecentrum.hu [110510 14:33]: On Tue, May 10, 2011 at 12:28:06 +0200, LEVAI Daniel wrote: On Tue, May 10, 2011 at 08:41:48 +0200, LEVAI Daniel wrote: On Mon, May 09, 2011 at 23:48:46 +0400, Alexander Polakov wrote: * Alexander Polakov polac...@gmail.com [110502 18:19]: Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? That diff was wrong, this one is likely less wrong. This is working fine for me. I've just found a usecase where it fails to complete a filename: $ touch 'aaa: bbb ccc' $ touch 'aaa: bbc ddd' $ ls -la aTAB $ ls -la aaa:\ bbTAB aaa: bbb ccc aaa: bbc ddd $ ls -la aaa:\ bbcTAB ^^^ nothing happens Apperantly, adding ':' to ESCAPEDCHARS solves the problem. Do you think there is any sideeffect to this? No, I don't think so. Let's just add it and find out in practice. 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 - 1.34 +++ bin/ksh/edit.c 10 May 2011 10:48:26 - @@ -357,20 +357,6 @@ toglob = add_glob(str, slen); - /* remove all escaping backward slashes */ - escaping = 0; - for (i = 0, idx = 0; toglob[i]; i++) { - if (toglob[i] == '\\' !escaping) { - escaping = 1; - continue; - } - - toglob[idx] = toglob[i]; - idx++; - if (escaping) escaping = 0; - } - toglob[idx] = '\0'; - /* * Convert foo* (toglob) to an array of strings (words) */ @@ -378,7 +364,7 @@ s = pushs(SWSTR, ATEMP); s-start = s-str = toglob; source = s; - if (yylex(ONEWORD) != LWORD) { + if (yylex(ONEWORD|RMBKSLSH) != LWORD) { source = sold; internal_errorf(0, fileglob: substitute error); return 0; @@ -394,6 +380,20 @@ if (nwords == 1) { struct stat statb; + /* remove all escaping backward slashes (see below) */ + escaping = 0; + for (i = 0, idx = 0; toglob[i]; i++) { + if (toglob[i] == '\\' !escaping) { + escaping = 1; + continue; + } + + toglob[idx] = toglob[i]; + idx++; + if (escaping) escaping = 0; + } + toglob[idx] = '\0'; + /* Check if globbing failed (returned glob pattern), * but be careful (E.g. toglob == ab* when the file * ab* exists is not an error). @@ -821,7 +821,7 @@ int rval = 0; for (add = 0, wlen = len; wlen - add 0; add++) { - if (strchr(\#$'()*;=?[\\]`{|}, s[add]) || + if (strchr(ESCAPEDCHARS, 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.45 diff -u -r1.45 lex.c --- bin/ksh/lex.c 9 Mar 2011 09:30:39 - 1.45 +++ bin/ksh/lex.c 10 May 2011 10:48:26 - @@ -299,6 +299,10 @@ } /* FALLTHROUGH */ default: + if ((cf RMBKSLSH) strchr( ESCAPEDCHARS, c)) { + *wp++ = QCHAR, *wp++ = c; + break; + } Xcheck(ws, wp); if (c) { /* trailing \ is lost */ *wp++ = CHAR, *wp++ = '\\'; 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 - 1.11 +++ bin/ksh/lex.h 10 May 2011 10:48:26 - @@ -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 RMBKSLSH BIT(11) /* remove backslashes */ #defineHERES 10 /* max in line */ Index: bin/ksh/sh.h === RCS file: /cvs/src/bin/ksh/sh.h,v retrieving revision 1.30 diff -u -r1.30 sh.h --- bin/ksh/sh.h4 Jan 2010 18:07:11 -
Re: ksh completion
* Alexander Polakov polac...@gmail.com [110502 18:19]: Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? That diff was wrong, this one is likely less wrong. 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 - 1.34 +++ bin/ksh/edit.c 9 May 2011 19:44:06 - @@ -357,20 +357,6 @@ toglob = add_glob(str, slen); - /* remove all escaping backward slashes */ - escaping = 0; - for (i = 0, idx = 0; toglob[i]; i++) { - if (toglob[i] == '\\' !escaping) { - escaping = 1; - continue; - } - - toglob[idx] = toglob[i]; - idx++; - if (escaping) escaping = 0; - } - toglob[idx] = '\0'; - /* * Convert foo* (toglob) to an array of strings (words) */ @@ -378,7 +364,7 @@ s = pushs(SWSTR, ATEMP); s-start = s-str = toglob; source = s; - if (yylex(ONEWORD) != LWORD) { + if (yylex(ONEWORD|RMBKSLSH) != LWORD) { source = sold; internal_errorf(0, fileglob: substitute error); return 0; @@ -394,6 +380,20 @@ if (nwords == 1) { struct stat statb; + /* remove all escaping backward slashes (see below) */ + escaping = 0; + for (i = 0, idx = 0; toglob[i]; i++) { + if (toglob[i] == '\\' !escaping) { + escaping = 1; + continue; + } + + toglob[idx] = toglob[i]; + idx++; + if (escaping) escaping = 0; + } + toglob[idx] = '\0'; + /* Check if globbing failed (returned glob pattern), * but be careful (E.g. toglob == ab* when the file * ab* exists is not an error). @@ -821,7 +821,7 @@ int rval = 0; for (add = 0, wlen = len; wlen - add 0; add++) { - if (strchr(\#$'()*;=?[\\]`{|}, s[add]) || + if (strchr(ESCAPEDCHARS, 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.45 diff -u -r1.45 lex.c --- bin/ksh/lex.c 9 Mar 2011 09:30:39 - 1.45 +++ bin/ksh/lex.c 9 May 2011 19:44:07 - @@ -299,6 +299,10 @@ } /* FALLTHROUGH */ default: + if ((cf RMBKSLSH) strchr( ESCAPEDCHARS, c)) { + *wp++ = QCHAR, *wp++ = c; + break; + } Xcheck(ws, wp); if (c) { /* trailing \ is lost */ *wp++ = CHAR, *wp++ = '\\'; 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 - 1.11 +++ bin/ksh/lex.h 9 May 2011 19:44:07 - @@ -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 RMBKSLSH BIT(11) /* remove backslashes */ #defineHERES 10 /* max in line */ Index: bin/ksh/sh.h === RCS file: /cvs/src/bin/ksh/sh.h,v retrieving revision 1.30 diff -u -r1.30 sh.h --- bin/ksh/sh.h4 Jan 2010 18:07:11 - 1.30 +++ bin/ksh/sh.h9 May 2011 19:44:07 - @@ -398,6 +398,9 @@ #define OBRACE '{' #define CBRACE '}' +/* Characters to be escaped */ +#define ESCAPEDCHARS \#$'()*;=?[\\]`{|} + /* Determine the location of the system (common) profile */ #define KSH_SYSTEM_PROFILE /etc/profile -- Alexander Polakov | plhk.ru
Re: ksh completion
* Martynas Venckus marty...@venck.us [110410 05:17]: hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). closes pr 6006 too. comments/ok? The diff is a workaround and even wrong. Ksh lexical analyzer itself has the ability to deal with escapes properly (see yylex). I believe we shouldn't remove backward slashes before passing it for analysis, this would fix all cases, including: $ touch aabbcc aa\*cc $ echo aa\*cctab aa*cc aabbcc $ echo aa\*cc aa*cc Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? 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 - 1.34 +++ bin/ksh/edit.c 2 May 2011 14:10:47 - @@ -357,20 +357,6 @@ toglob = add_glob(str, slen); - /* remove all escaping backward slashes */ - escaping = 0; - for (i = 0, idx = 0; toglob[i]; i++) { - if (toglob[i] == '\\' !escaping) { - escaping = 1; - continue; - } - - toglob[idx] = toglob[i]; - idx++; - if (escaping) escaping = 0; - } - toglob[idx] = '\0'; - /* * Convert foo* (toglob) to an array of strings (words) */ @@ -393,6 +379,20 @@ ; if (nwords == 1) { struct stat statb; + + /* remove all escaping backward slashes (see below) */ + escaping = 0; + for (i = 0, idx = 0; toglob[i]; i++) { + if (toglob[i] == '\\' !escaping) { + escaping = 1; + continue; + } + + toglob[idx] = toglob[i]; + idx++; + if (escaping) escaping = 0; + } + toglob[idx] = '\0'; /* Check if globbing failed (returned glob pattern), * but be careful (E.g. toglob == ab* when the file Index: bin/ksh/lex.c === RCS file: /cvs/src/bin/ksh/lex.c,v retrieving revision 1.45 diff -u -r1.45 lex.c --- bin/ksh/lex.c 9 Mar 2011 09:30:39 - 1.45 +++ bin/ksh/lex.c 2 May 2011 14:10:47 - @@ -287,24 +287,15 @@ switch (c) { case '\\': c = getsc(); - switch (c) { - case '\\': - case '$': case '`': + if ((c == '' ((cf HEREDOC) == 0)) || + strchr( \#$'()*;=?[\\]`{|}, c)) { *wp++ = QCHAR, *wp++ = c; break; - case '': - if ((cf HEREDOC) == 0) { - *wp++ = QCHAR, *wp++ = c; - break; - } - /* FALLTHROUGH */ - default: - Xcheck(ws, wp); - if (c) { /* trailing \ is lost */ - *wp++ = CHAR, *wp++ = '\\'; - *wp++ = CHAR, *wp++ = c; - } - break; + } + Xcheck(ws, wp); + if (c) { /* trailing \ is lost */ + *wp++ = CHAR, *wp++ = '\\'; + *wp++ = CHAR, *wp++ = c; } break; case '$': -- Alexander Polakov | plhk.ru
Re: ksh completion
On Mon, May 2, 2011 at 7:19 AM, Alexander Polakov polac...@gmail.com wrote: Do you mean something like this or I got it all wrong again and we have to wait another 15 years for someone to dig into this? I think ksh could really benefit from some regression tests to check that tab completion is behaving sanely. At the moment we have no real assurances that diffs don't break other tab completion scenarios. If anyone has clever ideas (preferably in proof-of-concept code form) on how to automate tab completion testing, that would help get support for this fix.
Re: ksh completion
Delivered-To: marty...@venck.us Received: by 10.231.147.205 with SMTP id m13cs105662ibv; Tue, 15 Mar 2011 01:48:25 -0700 (PDT) Received: by 10.43.46.135 with SMTP id uo7mr4936656icb.50.1300178905343; Tue, 15 Mar 2011 01:48:25 -0700 (PDT) Return-Path: owner-tech+m23...@openbsd.org Received: from shear.ucar.edu (lists.openbsd.org [192.43.244.163]) by mx.google.com with ESMTP id yd20si10108737icb.5.2011.03.15.01.48.25; Tue, 15 Mar 2011 01:48:25 -0700 (PDT) Received-SPF: pass (google.com: manual fallback record for domain of owner-tech+m23...@openbsd.org designates 192.43.244.163 as permitted sender) client-ip=192.43.244.163; Authentication-Results: mx.google.com; spf=pass (google.com: manual fallback record for domain of owner-tech+m23...@openbsd.org designates 192.43.244.163 as permitted sender) smtp.mail=owner-tech+m23...@openbsd.org Received: from openbsd.org (localhost.ucar.edu [127.0.0.1]) by shear.ucar.edu (8.14.3/8.14.3) with ESMTP id p2F8lBju030637; Tue, 15 Mar 2011 02:47:11 -0600 (MDT) Received: from clam.khaoz.org (clam.khaoz.org [64.90.163.62]) by shear.ucar.edu (8.14.3/8.14.3) with ESMTP id p2F8jjJq003536 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=FAIL); Tue, 15 Mar 2011 02:45:46 -0600 (MDT) Received: from clam.khaoz.org (okan@localhost [IPv6:::1]) by clam.khaoz.org (8.14.3/8.14.3) with ESMTP id p2F8jhx2026590 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Tue, 15 Mar 2011 04:45:44 -0400 (EDT) Date: Tue, 15 Mar 2011 04:45:43 -0400 From: Okan Demirmen o...@openbsd.org To: tech@openbsd.org Cc: r...@openbsd.org Subject: ksh completion Message-ID: 20110315084543.ga17...@clam.khaoz.org Mail-Followup-To: tech@openbsd.org, r...@openbsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Help: mailto:majord...@openbsd.org?body=help List-Owner: mailto:tech-ow...@openbsd.org List-Post: mailto:tech@openbsd.org List-Subscribe: mailto:majord...@openbsd.org?body=sub%20tech List-Unsubscribe: mailto:majord...@openbsd.org?body=unsub%20tech X-Loop: tech@openbsd.org Precedence: list Sender: owner-t...@openbsd.org hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). closes pr 6006 too. comments/ok? The diff is a workaround and even wrong. Ksh lexical analyzer itself has the ability to deal with escapes properly (see yylex). I believe we shouldn't remove backward slashes before passing it for analysis, this would fix all cases, including: $ touch aabbcc aa\*cc $ echo aa\*cctab aa*cc aabbcc $ echo aa\*cc aa*cc Index: edit.c === RCS file: /home/okan/hack/open/cvs/src/bin/ksh/edit.c,v retrieving revision 1.34 diff -u -p -r1.34 edit.c --- edit.c20 May 2010 01:13:07 - 1.34 +++ edit.c14 Mar 2011 09:59:27 - @@ -365,6 +365,11 @@ x_file_glob(int flags, const char *str, 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 @@ x_file_glob(int flags, const char *str, 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 @@ x_escape(const char *s, size_t len, int 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: lex.c === RCS file: /home/okan/hack/open/cvs/src/bin/ksh/lex.c,v retrieving revision 1.45 diff -u -p -r1.45 lex.c --- lex.c 9 Mar 2011 09:30:39 - 1.45 +++ lex.c 14 Mar 2011 09:59:27 - @@ -411,6 +411,13 @@ yylex(int cf) } } break; + case QCHAR: + if (cf LQCHAR) { + *wp++ = QCHAR; + *wp++ = getsc(); + break; + } + /* FALLTHROUGH
Re: ksh completion
On Thu, Mar 24, 2011 at 15:48:56 +0300, Alexander Polakov wrote: And just for the archives, a patch that really works as advertised (and using it for some time I feel like it *is* a good idea). One thing I've noticed: $ touch 'thing [another thing aaa' $ touch 'thing [another thing bbb' $ ls thingTAB $ ls thing\ \[another\ thing\ \\ now hitting 'a' or 'b' and then TAB does nothing. It does not complete further. However without the '[' character in the filename, it does. Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
Re: ksh completion
* Alexander Polakov polac...@gmail.com [110315 23:26]: * Federico G. Schwindt fg...@lodoss.net [110315 17:38]: I think I'm slightly confused as to you'd like fixed - do you mean that one shouldn't need to escape a '[' if it's the first character? (note that /bin/[ exists). Else, can you clarify a bit more? Thanks! correct, shouldn't need to escape a '[' if it's teh first character. i do know of [, but command and file completion are two different things. see bash too. I don't want to be defensive, but hey, how is bash relevant? [ is treated as a globbing character, you know. Is it first character or not, ksh doesn't care, it just tries to expand it. Oh well, you can try expanding it and then - if it failed - escape it and try again, like in the patch below. Bear in mind I didn't give it much thought, because I have a feeling it's not a good idea. And just for the archives, a patch that really works as advertised (and using it for some time I feel like it *is* a good idea). 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 - 1.34 +++ bin/ksh/edit.c 21 Mar 2011 13:38:04 - @@ -18,13 +18,14 @@ #include libgen.h #include sys/stat.h +#define ESCAPEDCHARS \#$'()*;=?[\\`{|} static void x_sigwinch(int); static volatile sig_atomic_t got_sigwinch; static void check_sigwinch(void); -static int x_file_glob(int, const char *, int, char ***); -static int x_command_glob(int, const char *, int, char ***); +static int x_file_glob(int, const char *, int, char ***, int); +static int x_command_glob(int, const char *, int, char ***, int); static int x_locate_word(const char *, int, int, int *, int *); @@ -344,10 +345,11 @@ * - returns number of matching strings */ static int -x_file_glob(int flags, const char *str, int slen, char ***wordsp) +x_file_glob(int flags, const char *str, int slen, char ***wordsp, int canrecurse) { char *toglob; char **words; + char *estr; int nwords, i, idx, escaping; XPtrV w; struct source *s, *sold; @@ -365,6 +367,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 +385,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; @@ -411,6 +418,21 @@ } afree(toglob, ATEMP); + /* Globbing failed, do escaping and try again. */ + if (!nwords !words canrecurse) { + estr = alloc(2 * slen + 1, ATEMP); + idx = 0; + for(i = 0; i slen; i++) { + if (strchr(ESCAPEDCHARS, str[i])) + estr[idx++] = '\\'; + estr[idx++] = str[i]; + } + estr[idx] = '\0'; + nwords = x_file_glob(flags, estr, idx, wordsp, !canrecurse); + afree(estr, ATEMP); + return nwords; + } + if (nwords) { *wordsp = words; } else if (words) { @@ -443,7 +465,7 @@ } static int -x_command_glob(int flags, const char *str, int slen, char ***wordsp) +x_command_glob(int flags, const char *str, int slen, char ***wordsp, int canrecurse) { char *toglob; char *pat; @@ -607,7 +629,7 @@ return 0; nwords = (is_command ? x_command_glob : x_file_glob)(flags, - buf + *startp, len, words); + buf + *startp, len, words, 1); if (nwords == 0) { *wordsp = (char **) 0; return 0; @@ -821,7 +843,7 @@ int rval = 0; for (add = 0, wlen = len; wlen - add 0; add++) { - if (strchr(\#$'()*;=?[\\]`{|}, s[add]) || + if (strchr(ESCAPEDCHARS, 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.45 diff -u -r1.45 lex.c --- bin/ksh/lex.c 9 Mar 2011 09:30:39 - 1.45 +++ bin/ksh/lex.c 21 Mar 2011 13:38:04 - @@ -411,6 +411,13 @@ } }
Re: ksh completion
On Thu, Mar 24, 2011 at 15:48:56 +0300, Alexander Polakov wrote: And just for the archives, a patch that really works as advertised (and using it for some time I feel like it *is* a good idea). It is really working well. Thanks! However, I don't quite understand why '[' needs to be escaped during completion: $ ls -la [\ ]\ [\ ]\ []\ ][ $ ls -la \[\ ]\ \[\ ]\ \[]\ ]\[ these two produce the same result: -rw-r--r-- 1 daniell daniell 0 Mar 24 15:38:38 2011 [ ] [ ] [] ][ Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
Re: ksh completion
On Thu, Mar 24, 2011 at 03:40:56PM +0100, LEVAI Daniel wrote: On Thu, Mar 24, 2011 at 15:48:56 +0300, Alexander Polakov wrote: And just for the archives, a patch that really works as advertised (and using it for some time I feel like it *is* a good idea). It is really working well. Thanks! However, I don't quite understand why '[' needs to be escaped during completion: $ ls -la [\ ]\ [\ ]\ []\ ][ $ ls -la \[\ ]\ \[\ ]\ \[]\ ]\[ these two produce the same result: -rw-r--r-- 1 daniell daniell 0 Mar 24 15:38:38 2011 [ ] [ ] [] ][ for the following for example: $ touch adef '[abc]def' $ ls [abc]def adef $ ls \[abc]def [abc]def $ Daniel Janjaap van Velthooven -- / __/ /_/ __/ /_ __/ __/ /___ / / /_ __/___/_/_ /___ / / __/ /___ / / janj...@stack.nl /___/_/_/_/_/_/_/___/_/_/
Re: ksh completion
On Thu, Mar 24, 2011 at 16:30:12 +0100, Janjaap van Velthooven wrote: On Thu, Mar 24, 2011 at 03:40:56PM +0100, LEVAI Daniel wrote: On Thu, Mar 24, 2011 at 15:48:56 +0300, Alexander Polakov wrote: And just for the archives, a patch that really works as advertised (and using it for some time I feel like it *is* a good idea). It is really working well. Thanks! However, I don't quite understand why '[' needs to be escaped during completion: $ ls -la [\ ]\ [\ ]\ []\ ][ $ ls -la \[\ ]\ \[\ ]\ \[]\ ]\[ these two produce the same result: -rw-r--r-- 1 daniell daniell 0 Mar 24 15:38:38 2011 [ ] [ ] [] ][ for the following for example: $ touch adef '[abc]def' $ ls [abc]def adef $ ls \[abc]def [abc]def $ Oh, how marvelous! Thanks! Daniel -- LIVAI Daniel PGP key ID = 0x83B63A8F Key fingerprint = DBEC C66B A47A DFA2 792D 650C C69B BE4C 83B6 3A8F
ksh completion
hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). closes pr 6006 too. comments/ok? Index: edit.c === RCS file: /home/okan/hack/open/cvs/src/bin/ksh/edit.c,v retrieving revision 1.34 diff -u -p -r1.34 edit.c --- edit.c 20 May 2010 01:13:07 - 1.34 +++ edit.c 14 Mar 2011 09:59:27 - @@ -365,6 +365,11 @@ x_file_glob(int flags, const char *str, 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 @@ x_file_glob(int flags, const char *str, 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 @@ x_escape(const char *s, size_t len, int 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: lex.c === RCS file: /home/okan/hack/open/cvs/src/bin/ksh/lex.c,v retrieving revision 1.45 diff -u -p -r1.45 lex.c --- lex.c 9 Mar 2011 09:30:39 - 1.45 +++ lex.c 14 Mar 2011 09:59:27 - @@ -411,6 +411,13 @@ yylex(int cf) } } break; + case QCHAR: + if (cf LQCHAR) { + *wp++ = QCHAR; + *wp++ = getsc(); + break; + } + /* FALLTHROUGH */ default: *wp++ = CHAR, *wp++ = c; } Index: lex.h === RCS file: /home/okan/hack/open/cvs/src/bin/ksh/lex.h,v retrieving revision 1.11 diff -u -p -r1.11 lex.h --- lex.h 29 May 2006 18:22:24 - 1.11 +++ lex.h 14 Mar 2011 09:59:27 - @@ -113,6 +113,7 @@ typedef union { #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 */ #defineHERES 10 /* max in line */
Re: ksh completion
On Tue 2011.03.15 at 12:19 +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 04:45:43AM -0400, Okan Demirmen wrote: hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). This diff doesn't work for me with files containing '['. This is the first character I tested and it failed. $ touch [this] file.txt $ cat [TAB --- nothing You still need to escape these characters. cat \[TAB -- should now work.
Re: ksh completion
On Tue, Mar 15, 2011 at 06:47:22AM -0400, Okan Demirmen wrote: On Tue 2011.03.15 at 12:19 +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 04:45:43AM -0400, Okan Demirmen wrote: hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). This diff doesn't work for me with files containing '['. This is the first character I tested and it failed. $ touch [this] file.txt $ cat [TAB --- nothing You still need to escape these characters. cat \[TAB -- should now work. Okay, tested with all the characters and it works. After reading the diff it looks okay to me, but take into consideration that I'm not well aquainted with this part of the tree and I'm biased because I really want to have this functionality in ksh!
Re: ksh completion
On Tue, Mar 15, 2011 at 01:00:30PM +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 06:47:22AM -0400, Okan Demirmen wrote: On Tue 2011.03.15 at 12:19 +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 04:45:43AM -0400, Okan Demirmen wrote: hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). This diff doesn't work for me with files containing '['. This is the first character I tested and it failed. $ touch [this] file.txt $ cat [TAB --- nothing You still need to escape these characters. cat \[TAB -- should now work. Okay, tested with all the characters and it works. After reading the diff it looks okay to me, but take into consideration that I'm not well aquainted with this part of the tree and I'm biased because I really want to have this functionality in ksh! this is what the diff is really fixing. escaping of []'s already works as long as [ is not the first character, even if it's escaped. i'd like to see this but without the need to escape [ to be honest. f.-
Re: ksh completion
On Tue 2011.03.15 at 11:14 +, Federico G. Schwindt wrote: On Tue, Mar 15, 2011 at 01:00:30PM +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 06:47:22AM -0400, Okan Demirmen wrote: On Tue 2011.03.15 at 12:19 +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 04:45:43AM -0400, Okan Demirmen wrote: hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). This diff doesn't work for me with files containing '['. This is the first character I tested and it failed. $ touch [this] file.txt $ cat [TAB --- nothing You still need to escape these characters. cat \[TAB -- should now work. Okay, tested with all the characters and it works. After reading the diff it looks okay to me, but take into consideration that I'm not well aquainted with this part of the tree and I'm biased because I really want to have this functionality in ksh! this is what the diff is really fixing. escaping of []'s already works as long as [ is not the first character, even if it's escaped. i'd like to see this but without the need to escape [ to be honest. I think I'm slightly confused as to you'd like fixed - do you mean that one shouldn't need to escape a '[' if it's the first character? (note that /bin/[ exists). Else, can you clarify a bit more? Thanks! Cheers, Okan
Re: ksh completion
On Tue, Mar 15, 2011 at 11:14:09AM +, Federico G. Schwindt wrote: On Tue, Mar 15, 2011 at 01:00:30PM +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 06:47:22AM -0400, Okan Demirmen wrote: On Tue 2011.03.15 at 12:19 +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 04:45:43AM -0400, Okan Demirmen wrote: hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). This diff doesn't work for me with files containing '['. This is the first character I tested and it failed. $ touch [this] file.txt $ cat [TAB --- nothing You still need to escape these characters. cat \[TAB -- should now work. Okay, tested with all the characters and it works. After reading the diff it looks okay to me, but take into consideration that I'm not well aquainted with this part of the tree and I'm biased because I really want to have this functionality in ksh! this is what the diff is really fixing. escaping of []'s already works as long as [ is not the first character, even if it's escaped. No it does not. If you have a [ somewhere inside a filename the completion stops there. BEFORE: $ touch this [is] it $ touch this [isn't] it $ cat thTAB - this\ \[is Now type 'n': $ cat this\ \[isnTAB - nothing happens AFTER: $ touch this [is] it $ touch this [isn't] it $ cat thTAB - this\ \[is Now type 'n': $ cat this\ \[isn\'t\]\ it This is good to have in the tree in the year of our lord two thousand eleven. i'd like to see this but without the need to escape [ to be honest. I don't think that's possible due to the stupidity of the '[' executable.
Re: ksh completion
On Tue, Mar 15, 2011 at 03:13:45PM +0200, Paul Irofti wrote: |i'd like to see this but without the need to escape [ to be honest. | | I don't think that's possible due to the stupidity of the '[' executable. What does /bin/[ have to do with completion of filenames ? You can `cd ~; touch ifconfig; cat ifcTAB` and have it complete to 'ifconfig'. If you were to `cd ~; touch ifconfig; ifcTAB`, it would still complete to the command ifconfig. Same as with /bin/[, just with the caveat that this will get escaped. What Federico wants (I think) is type '[' (without the escaping backslash) and have it complete after that (filling in the backslashes where needed). It works for the command /bin/[ with the current /bin/ksh, but not for filenames containing [. Of course 'completing' a one-character command is a bit counterproductive, but it works like a charm ;) Paul 'WEiRD' de Weerd -- [++-]+++.+++[---].+++[+ +++-].++[-]+.--.[-] http://www.weirdnet.nl/
Re: ksh completion
On Tue, Mar 15, 2011 at 08:39:48AM -0400, Okan Demirmen wrote: On Tue 2011.03.15 at 11:14 +, Federico G. Schwindt wrote: On Tue, Mar 15, 2011 at 01:00:30PM +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 06:47:22AM -0400, Okan Demirmen wrote: On Tue 2011.03.15 at 12:19 +0200, Paul Irofti wrote: On Tue, Mar 15, 2011 at 04:45:43AM -0400, Okan Demirmen wrote: hi, (this is a re-post) make tab completion work for '=', '`', '[', ':', and '$' - pulled from mksh by Alexander Polakov (also posted to tech recently). This diff doesn't work for me with files containing '['. This is the first character I tested and it failed. $ touch [this] file.txt $ cat [TAB --- nothing You still need to escape these characters. cat \[TAB -- should now work. Okay, tested with all the characters and it works. After reading the diff it looks okay to me, but take into consideration that I'm not well aquainted with this part of the tree and I'm biased because I really want to have this functionality in ksh! this is what the diff is really fixing. escaping of []'s already works as long as [ is not the first character, even if it's escaped. i'd like to see this but without the need to escape [ to be honest. I think I'm slightly confused as to you'd like fixed - do you mean that one shouldn't need to escape a '[' if it's the first character? (note that /bin/[ exists). Else, can you clarify a bit more? Thanks! correct, shouldn't need to escape a '[' if it's teh first character. i do know of [, but command and file completion are two different things. see bash too. f.-
Re: ksh completion
* Federico G. Schwindt fg...@lodoss.net [110315 17:38]: I think I'm slightly confused as to you'd like fixed - do you mean that one shouldn't need to escape a '[' if it's the first character? (note that /bin/[ exists). Else, can you clarify a bit more? Thanks! correct, shouldn't need to escape a '[' if it's teh first character. i do know of [, but command and file completion are two different things. see bash too. I don't want to be defensive, but hey, how is bash relevant? [ is treated as a globbing character, you know. Is it first character or not, ksh doesn't care, it just tries to expand it. Oh well, you can try expanding it and then - if it failed - escape it and try again, like in the patch below. Bear in mind I didn't give it much thought, because I have a feeling it's not a good idea. diff --git a/edit.c b/edit.c index 4cff25b..eee8a5d 100644 --- a/edit.c +++ b/edit.c @@ -18,6 +18,7 @@ #include libgen.h #include sys/stat.h +#define ESCAPEDCHARS \#$'()*;=?[\\`{|} static void x_sigwinch(int); static volatile sig_atomic_t got_sigwinch; @@ -348,6 +349,7 @@ x_file_glob(int flags, const char *str, int slen, char ***wordsp) { char *toglob; char **words; + char *estr; int nwords, i, idx, escaping; XPtrV w; struct source *s, *sold; @@ -416,6 +418,21 @@ x_file_glob(int flags, const char *str, int slen, char ***wordsp) } afree(toglob, ATEMP); + /* Globbing failed, do escaping and try again. */ + if (!nwords !words) { + estr = alloc(2 * slen + 1, ATEMP); + idx = 0; + for(i = 0; i slen; i++) { + if (strchr(ESCAPEDCHARS, str[i])) + estr[idx++] = '\\'; + estr[idx++] = str[i]; + } + estr[idx] = '\0'; + nwords = x_file_glob(flags, estr, idx, wordsp); + afree(estr, ATEMP); + return nwords; + } + if (nwords) { *wordsp = words; } else if (words) { @@ -826,7 +843,7 @@ x_escape(const char *s, size_t len, int (*putbuf_func) (const char *, size_t)) int rval = 0; for (add = 0, wlen = len; wlen - add 0; add++) { - if (strchr(\#$'()*;=?[\\`{|}, s[add]) || + if (strchr(ESCAPEDCHARS, s[add]) || strchr(ifs, s[add])) { if (putbuf_func(s, add) != 0) { rval = -1; -- Alexander Polakov | plhk.ru
Re: ksh completion for [, :, $
On Fri, Feb 4, 2011 at 1:42 PM, Alexander Polakov polac...@gmail.com 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
ksh completion for [, :, $
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 +; 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 - 1.34 +++ bin/ksh/edit.c 4 Feb 2011 17:58:48 - @@ -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 - 1.44 +++ bin/ksh/lex.c 4 Feb 2011 17:58:48 - @@ -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 - 1.11 +++ bin/ksh/lex.h 4 Feb 2011 17:58:48 - @@ -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 */ #defineHERES 10 /* max in line */ -- Alexander Polakov | plhk.ru