Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15486 > unrolled thread
| Started by | Муравьев Александр <amuravyev@s-terra.ru> |
|---|---|
| First post | 2019-10-08 20:30 +0300 |
| Last post | 2019-10-08 20:30 +0300 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
compgen -F Муравьев Александр <amuravyev@s-terra.ru> - 2019-10-08 20:30 +0300
| From | Муравьев Александр <amuravyev@s-terra.ru> |
|---|---|
| Date | 2019-10-08 20:30 +0300 |
| Subject | compgen -F |
| Message-ID | <mailman.1392.1570555848.2651.bug-bash@gnu.org> |
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",
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)
> char *word, **matches;
> char *old_line;
> int old_ind;
> + char pcomp_local[4096];
> + char *last_word = NULL;
>
> if (list == 0)
> return (EXECUTION_SUCCESS);
> @@ -753,9 +755,55 @@ compgen_builtin (list)
> /* probably don't have to save these, just being safe */
> old_line = pcomp_line;
> old_ind = pcomp_ind;
> - pcomp_line = (char *)NULL;
> - pcomp_ind = 0;
> - sl = gen_compspec_completions (cs, "compgen", word, 0, 0, 0);
> +
> + {
> + WORD_LIST *cword = list;
> + if (cword && cword->word
> + && strlen(cword->word->word) > 0)
> + {
> + last_word = cword->word->word;
> + }
> + *pcomp_local = '\0';
> + if (cword && cword->word)
> + {
> + strcat(pcomp_local, cword->word->word);
> + if (strlen(cword->word->word) > 0)
> + {
> + last_word = cword->word->word;
> + }
> + cword = cword->next;
> + }
> + while (cword)
> + {
> + if (strlen(cword->word->word) > 0)
> + {
> + last_word = cword->word->word;
> + }
> + strcat(pcomp_local, " ");
> + strcat(pcomp_local, cword->word->word);
> + cword = cword->next;
> + }
> + }
> + pcomp_line = pcomp_local;
> + pcomp_ind = strlen(pcomp_local);
> +
> + sl = gen_compspec_completions (cs, "compgen", word, 0, pcomp_ind, 0);
> + if (sl != 0 && sl->list_len == 1)
> + {
> + int last_word_len = strlen(last_word);
> + int strcmp_complete_res = strncmp(*(sl->list), last_word,
> + last_word_len);
> + if (0 == strcmp_complete_res
> + && strlen(*(sl->list)) == last_word_len + 1
> + && (*(sl->list))[last_word_len] == ' ')
> + {
> + /* User already enter this word. Go to next one. */
> + strcat(pcomp_local, " ");
> + pcomp_ind++;
> + sl = gen_compspec_completions (cs, "compgen", word, 0,
> pcomp_ind, 0);
> + }
> + }
> +
> pcomp_line = old_line;
> pcomp_ind = old_ind;
>
Back to top | Article view | gnu.bash.bug
csiph-web