Path: csiph.com!news.mixmin.net!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: =?UTF-8?B?0JzRg9GA0LDQstGM0LXQsiDQkNC70LXQutGB0LDQvdC00YA=?= Newsgroups: gnu.bash.bug Subject: compgen -F Date: Tue, 8 Oct 2019 20:30:24 +0300 Lines: 109 Approved: bug-bash@gnu.org Message-ID: References: <85ae4659-49c5-26d8-a241-03e78c4f41a8@s-terra.ru> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Trace: usenet.stanford.edu 1570555848 9835 209.51.188.17 (8 Oct 2019 17:30:48 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=s-terra.ru; s=mail; t=1570555824; bh=xkCQCc84CLeAGoigIHYXV8CT1ZVL4qjbQrSi7Ehn32M=; h=To:From:Subject:Date:From; b=Ix+/8jGVNC5obTYHbaE3rlCUXqGWngRqMWNAgQflnjlWT63O9dRSTYBXLnl2E7nTP QHU8imM707L1rJ/utkPt/xouZluuh1E+thTuNT4bX78IIBxTabFhmqhXlCaJT0T8P6 HmKZtPCSF0SQ2dxRyQC9kJoMiA6OEW6V6AVmfMzU= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 Content-Language: en-US X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 193.164.201.59 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <85ae4659-49c5-26d8-a241-03e78c4f41a8@s-terra.ru> Xref: csiph.com gnu.bash.bug:15486 Hello! I am unable to use "compgen -F" and made a patch to make it works. Please, tell me how to improve it (if it is ugly). Hope that it will be possible to use "compgen -F" in new BASH version. My BASH version is "5.0.11(11)-release", OS "Ubuntu 18.04.3 LTS",=20 machine "x86_64". Here it is: > diff --git a/builtins/complete.def b/builtins/complete.def > index 76b3eedd..e253fc60 100644 > --- a/builtins/complete.def > +++ b/builtins/complete.def > @@ -709,6 +709,8 @@ compgen_builtin (list) > =C2=A0=C2=A0 char *word, **matches; > =C2=A0=C2=A0 char *old_line; > =C2=A0=C2=A0 int old_ind; > +=C2=A0 char pcomp_local[4096]; > +=C2=A0 char *last_word =3D NULL; > > =C2=A0=C2=A0 if (list =3D=3D 0) > =C2=A0=C2=A0=C2=A0=C2=A0 return (EXECUTION_SUCCESS); > @@ -753,9 +755,55 @@ compgen_builtin (list) > =C2=A0=C2=A0 /* probably don't have to save these, just being safe */ > =C2=A0=C2=A0 old_line =3D pcomp_line; > =C2=A0=C2=A0 old_ind =3D pcomp_ind; > -=C2=A0 pcomp_line =3D (char *)NULL; > -=C2=A0 pcomp_ind =3D 0; > -=C2=A0 sl =3D gen_compspec_completions (cs, "compgen", word, 0, 0, 0); > + > +=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 WORD_LIST *cword =3D list; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (cword && cword->word > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && strlen(cword= ->word->word) > 0) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 last_word =3D c= word->word->word; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 *pcomp_local =3D '\0'; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (cword && cword->word) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 strcat(pcomp_lo= cal, cword->word->word); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (strlen(cwor= d->word->word) > 0) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 last_word =3D cword->word->word; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cword =3D cword= ->next; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 while (cword) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (strlen(cwor= d->word->word) > 0) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 last_word =3D cword->word->word; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 strcat(pcomp_lo= cal, " "); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 strcat(pcomp_lo= cal, cword->word->word); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 cword =3D cword= ->next; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > +=C2=A0 } > +=C2=A0 pcomp_line =3D pcomp_local; > +=C2=A0 pcomp_ind =3D strlen(pcomp_local); > + > +=C2=A0 sl =3D gen_compspec_completions (cs, "compgen", word, 0, pcomp_= ind, 0); > +=C2=A0 if (sl !=3D 0 && sl->list_len =3D=3D 1) > +=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int last_word_len =3D strlen(last_word)= ; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 int strcmp_complete_res =3D strncmp(*(s= l->list), last_word, > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0 last_word_len); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 if (0 =3D=3D strcmp_complete_res > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && = strlen(*(sl->list)) =3D=3D last_word_len + 1 > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && = (*(sl->list))[last_word_len] =3D=3D ' ') > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 { > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* User already enter this = word. Go to next one. */ > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 strcat(pcomp_local, " "); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 pcomp_ind++; > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sl =3D gen_compspec_complet= ions (cs, "compgen", word, 0,=20 > pcomp_ind, 0); > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 } > +=C2=A0 } > + > =C2=A0=C2=A0 pcomp_line =3D old_line; > =C2=A0=C2=A0 pcomp_ind =3D old_ind; >