diff -uNr bash-2.05.orig/builtins/complete.def bash-2.05/builtins/complete.def --- bash-2.05.orig/builtins/complete.def Wed Feb 14 14:07:54 2001 +++ bash-2.05/builtins/complete.def Thu May 10 20:06:06 2001 @@ -24,7 +24,7 @@ $BUILTIN complete $DEPENDS_ON PROGRAMMABLE_COMPLETION $FUNCTION complete_builtin -$SHORT_DOC complete [-abcdefjkvu] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...] +$SHORT_DOC complete [-abcdefgjkvu] [-pr] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [name ...] For each NAME, specify how arguments are to be completed. If the -p option is supplied, or if no options are supplied, existing completion specifications are printed in a way that allows them to be @@ -76,6 +76,7 @@ { "export", CA_EXPORT, 'e' }, { "file", CA_FILE, 'f' }, { "function", CA_FUNCTION, 0 }, + { "group", CA_GROUP, 'g' }, { "helptopic", CA_BUILTIN, 0 }, /* for now */ { "hostname", CA_HOSTNAME, 0 }, { "job", CA_JOB, 'j' }, @@ -151,7 +152,7 @@ opt_given = 0; reset_internal_getopt (); - while ((opt = internal_getopt (list, "abcdefjko:pruvA:G:W:P:S:X:F:C:")) != -1) + while ((opt = internal_getopt (list, "abcdefgjko:pruvA:G:W:P:S:X:F:C:")) != -1) { opt_given = 1; switch (opt) @@ -200,6 +201,9 @@ case 'f': acts |= CA_FILE; break; + case 'g': + acts |= CA_GROUP; + break; case 'j': acts |= CA_JOB; break; @@ -424,6 +428,7 @@ PRINTOPT (CA_DIRECTORY, "-d"); PRINTOPT (CA_EXPORT, "-e"); PRINTOPT (CA_FILE, "-f"); + PRINTOPT (CA_GROUP, "-g"); PRINTOPT (CA_KEYWORD, "-k"); PRINTOPT (CA_JOB, "-j"); PRINTOPT (CA_USER, "-u"); @@ -490,7 +495,7 @@ $BUILTIN compgen $DEPENDS_ON PROGRAMMABLE_COMPLETION $FUNCTION compgen_builtin -$SHORT_DOC compgen [-abcdefjkvu] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word] +$SHORT_DOC compgen [-abcdefgjkvu] [-o option] [-A action] [-G globpat] [-W wordlist] [-P prefix] [-S suffix] [-X filterpat] [-F function] [-C command] [word] Display the possible completions depending on the options. Intended to be used from within a shell function generating possible completions. If the optional WORD argument is supplied, matches against WORD are diff -uNr bash-2.05.orig/doc/bash.1 bash-2.05/doc/bash.1 --- bash-2.05.orig/doc/bash.1 Thu May 10 20:27:15 2001 +++ bash-2.05/doc/bash.1 Thu May 10 20:06:06 2001 @@ -5678,7 +5678,7 @@ matches were generated. .TP .PD 0 -\fBcomplete\fP [\fB\-abcdefjkvu\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] +\fBcomplete\fP [\fB\-abcdefgjkvu\fP] [\fB\-o\fP \fIcomp-option\fP] [\fB\-A\fP \fIaction\fP] [\fB\-G\fP \fIglobpat\fP] [\fB\-W\fP \fIwordlist\fP] [\fB\-P\fP \fIprefix\fP] [\fB\-S\fP \fIsuffix\fP] .br [\fB\-X\fP \fIfilterpat\fP] [\fB\-F\fP \fIfunction\fP] [\fB\-C\fP \fIcommand\fP] \fIname\fP [\fIname ...\fP] .TP @@ -5759,6 +5759,9 @@ .TP 8 .B function Names of shell functions. +.TP 8 +.B group +Group names. May also be specified as \fB\-g\fP. .TP 8 .B helptopic Help topics as accepted by the \fBhelp\fP builtin. diff -uNr bash-2.05.orig/lib/readline/complete.c bash-2.05/lib/readline/complete.c --- bash-2.05.orig/lib/readline/complete.c Wed Feb 14 04:47:18 2001 +++ bash-2.05/lib/readline/complete.c Thu May 10 20:25:05 2001 @@ -49,6 +49,7 @@ #endif /* !errno */ #include +#include #include "posixdir.h" #include "posixstat.h" @@ -71,6 +72,7 @@ defined. */ #if !defined (HAVE_GETPW_DECLS) || defined (_POSIX_SOURCE) extern struct passwd *getpwent __P((void)); +extern struct group *getgrent __P((void)); #endif /* !HAVE_GETPW_DECLS || _POSIX_SOURCE */ /* If non-zero, then this is the address of a function to call when @@ -1436,6 +1438,58 @@ if (first_char == '~') rl_filename_completion_desired = 1; + + return (value); + } +#endif /* !__WIN32__ && !__OPENNT */ +} + +/* A completion function for groupnames. + TEXT contains a partial groupname. */ +char * +rl_groupname_completion_function (text, state) + const char *text; + int state; +{ +#if defined (__WIN32__) || defined (__OPENNT) + return (char *)NULL; +#else /* !__WIN32__ && !__OPENNT) */ + static char *groupname = (char *)NULL; + static struct group *entry; + static int namelen, first_char; + char *value; + + if (state == 0) + { + FREE (groupname); + + first_char = *text; + + groupname = savestring (&text[0]); + namelen = strlen (groupname); + setgrent (); + } + + while (entry = getgrent ()) + { + /* Null groupnames should result in all groups as possible + completions. */ + if (namelen == 0 || (STREQN (groupname, entry->gr_name, namelen))) + break; + } + + if (entry == 0) + { + endgrent (); + return ((char *)NULL); + } + else + { + value = xmalloc (2 + strlen (entry->gr_name)); + + *value = *text; + + strcpy (value, entry->gr_name); return (value); } diff -uNr bash-2.05.orig/lib/readline/readline.h bash-2.05/lib/readline/readline.h --- bash-2.05.orig/lib/readline/readline.h Wed Feb 14 13:27:54 2001 +++ bash-2.05/lib/readline/readline.h Thu May 10 20:06:06 2001 @@ -409,6 +409,7 @@ extern char **rl_completion_matches __P((const char *, rl_compentry_func_t *)); extern char *rl_username_completion_function __P((const char *, int)); +extern char *rl_groupname_completion_function __P((const char *, int)); extern char *rl_filename_completion_function __P((const char *, int)); #if 0 diff -uNr bash-2.05.orig/pcomplete.c bash-2.05/pcomplete.c --- bash-2.05.orig/pcomplete.c Wed Feb 14 13:59:55 2001 +++ bash-2.05/pcomplete.c Thu May 10 20:13:54 2001 @@ -116,6 +116,7 @@ ITEMLIST it_exports = { LIST_DYNAMIC, it_init_exported, (STRINGLIST *)0 }; ITEMLIST it_files = { LIST_DYNAMIC }; /* unused */ ITEMLIST it_functions = { 0, it_init_functions, (STRINGLIST *)0 }; +ITEMLIST it_groups = { LIST_DYNAMIC }; /* unused */ ITEMLIST it_hostnames = { LIST_DYNAMIC, it_init_hostnames, (STRINGLIST *)0 }; ITEMLIST it_jobs = { LIST_DYNAMIC, it_init_jobs, (STRINGLIST *)0 };; ITEMLIST it_keywords = { 0, it_init_keywords, (STRINGLIST *)0 }; @@ -722,6 +723,7 @@ GEN_XCOMPS(flags, CA_COMMAND, text, command_word_completion_function, cmatches, ret, tmatches); GEN_XCOMPS(flags, CA_FILE, text, pcomp_filename_completion_function, cmatches, ret, tmatches); + GEN_XCOMPS(flags, CA_GROUP, text, rl_groupname_completion_function, cmatches, ret, tmatches); GEN_XCOMPS(flags, CA_USER, text, rl_username_completion_function, cmatches, ret, tmatches); /* And lastly, the special case for directories */ diff -uNr bash-2.05.orig/pcomplete.h bash-2.05/pcomplete.h --- bash-2.05.orig/pcomplete.h Mon Nov 27 09:33:05 2000 +++ bash-2.05/pcomplete.h Thu May 10 20:06:07 2001 @@ -51,17 +51,18 @@ #define CA_EXPORT (1<<8) #define CA_FILE (1<<9) #define CA_FUNCTION (1<<10) -#define CA_HELPTOPIC (1<<11) -#define CA_HOSTNAME (1<<12) -#define CA_JOB (1<<13) -#define CA_KEYWORD (1<<14) -#define CA_RUNNING (1<<15) -#define CA_SETOPT (1<<16) -#define CA_SHOPT (1<<17) -#define CA_SIGNAL (1<<18) -#define CA_STOPPED (1<<19) -#define CA_USER (1<<20) -#define CA_VARIABLE (1<<21) +#define CA_GROUP (1<<11) +#define CA_HELPTOPIC (1<<12) +#define CA_HOSTNAME (1<<13) +#define CA_JOB (1<<14) +#define CA_KEYWORD (1<<15) +#define CA_RUNNING (1<<16) +#define CA_SETOPT (1<<17) +#define CA_SHOPT (1<<18) +#define CA_SIGNAL (1<<19) +#define CA_STOPPED (1<<20) +#define CA_USER (1<<21) +#define CA_VARIABLE (1<<22) /* Values for COMPSPEC options field. */ #define COPT_RESERVED (1<<0) /* reserved for other use */ @@ -106,6 +107,7 @@ extern ITEMLIST it_exports; extern ITEMLIST it_files; extern ITEMLIST it_functions; +extern ITEMLIST it_groups; extern ITEMLIST it_hostnames; extern ITEMLIST it_jobs; extern ITEMLIST it_keywords;