1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-03 10:21:46 +02:00

35193: Add "unalias -a".

This commit is contained in:
Peter Stephenson 2015-05-18 16:56:36 +01:00
parent 2caa5ddd79
commit ff19094669
5 changed files with 59 additions and 8 deletions

View file

@ -1,5 +1,8 @@
2015-05-18 Peter Stephenson <p.stephenson@samsung.com> 2015-05-18 Peter Stephenson <p.stephenson@samsung.com>
* 35193: Doc/Zsh/builtins.yo, Src/builtin.c, Src/hashtable.h,
Test/A02alias.ztst: add "unalias -a".
* 35187: Completion/Unix/Command/_vim: fix unbalanced parentheses. * 35187: Completion/Unix/Command/_vim: fix unbalanced parentheses.
* 35184: Src/parse.c, Test/A01grammar.ztst: fix pattern parsing * 35184: Src/parse.c, Test/A01grammar.ztst: fix pattern parsing

View file

@ -2056,7 +2056,14 @@ the symbolic form the permissions you specify are those which are to be
allowed (not denied) to the users specified. allowed (not denied) to the users specified.
) )
cindex(aliases, removing) cindex(aliases, removing)
alias(unalias)(unhash -a) item(tt(unalias) [ tt(-ams) ] var(name) ...)(
Removes aliases. This command works the same as tt(unhash -a), except that
the tt(-a) option removes all regular or global aliases, or with tt(-s)
all suffix aliases: in this case no var(name) arguments may appear. The
options tt(-m) (remove by pattern) and tt(-s) without tt(-a) (remove
listed suffix aliases) behave as for tt(unhash -a). Note that
the meaning of tt(-a) is different between tt(unalias) and tt(unhash).
)
cindex(functions, removing) cindex(functions, removing)
alias(unfunction)(unhash -f) alias(unfunction)(unhash -f)
findex(unhash) findex(unhash)

View file

@ -122,9 +122,9 @@ static struct builtin builtins[] =
BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfsSw", "v"), BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfsSw", "v"),
BUILTIN("typeset", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%klprtuxmz", NULL), BUILTIN("typeset", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%klprtuxmz", NULL),
BUILTIN("umask", 0, bin_umask, 0, 1, 0, "S", NULL), BUILTIN("umask", 0, bin_umask, 0, 1, 0, "S", NULL),
BUILTIN("unalias", 0, bin_unhash, 1, -1, 0, "ms", "a"), BUILTIN("unalias", 0, bin_unhash, 0, -1, BIN_UNALIAS, "ams", NULL),
BUILTIN("unfunction", 0, bin_unhash, 1, -1, 0, "m", "f"), BUILTIN("unfunction", 0, bin_unhash, 1, -1, BIN_UNFUNCTION, "m", "f"),
BUILTIN("unhash", 0, bin_unhash, 1, -1, 0, "adfms", NULL), BUILTIN("unhash", 0, bin_unhash, 1, -1, BIN_UNHASH, "adfms", NULL),
BUILTIN("unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fmv", NULL), BUILTIN("unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fmv", NULL),
BUILTIN("unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL), BUILTIN("unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL),
BUILTIN("wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL), BUILTIN("wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL),
@ -3557,26 +3557,54 @@ bin_hash(char *name, char **argv, Options ops, UNUSED(int func))
/**/ /**/
int int
bin_unhash(char *name, char **argv, Options ops, UNUSED(int func)) bin_unhash(char *name, char **argv, Options ops, int func)
{ {
HashTable ht; HashTable ht;
HashNode hn, nhn; HashNode hn, nhn;
Patprog pprog; Patprog pprog;
int match = 0, returnval = 0; int match = 0, returnval = 0, all = 0;
int i; int i;
/* Check which hash table we are working with. */ /* Check which hash table we are working with. */
if (OPT_ISSET(ops,'d')) if (func == BIN_UNALIAS) {
if (OPT_ISSET(ops,'s'))
ht = sufaliastab; /* suffix aliases */
else
ht = aliastab; /* aliases */
if (OPT_ISSET(ops, 'a')) {
if (*argv) {
zwarnnam(name, "-a: too many arguments");
return 1;
}
all = 1;
} else if (!*argv) {
zwarnnam(name, "not enough arguments");
return 1;
}
} else if (OPT_ISSET(ops,'d'))
ht = nameddirtab; /* named directories */ ht = nameddirtab; /* named directories */
else if (OPT_ISSET(ops,'f')) else if (OPT_ISSET(ops,'f'))
ht = shfunctab; /* shell functions */ ht = shfunctab; /* shell functions */
else if (OPT_ISSET(ops,'s')) else if (OPT_ISSET(ops,'s'))
ht = sufaliastab; /* suffix aliases, must precede aliases */ ht = sufaliastab; /* suffix aliases, must precede aliases */
else if (OPT_ISSET(ops,'a')) else if (func == BIN_UNHASH && (OPT_ISSET(ops,'a')))
ht = aliastab; /* aliases */ ht = aliastab; /* aliases */
else else
ht = cmdnamtab; /* external commands */ ht = cmdnamtab; /* external commands */
if (all) {
queue_signals();
for (i = 0; i < ht->hsize; i++) {
for (hn = ht->nodes[i]; hn; hn = nhn) {
/* record pointer to next, since we may free this one */
nhn = hn->next;
ht->freenode(ht->removenode(ht, hn->nam));
}
}
unqueue_signals();
return 0;
}
/* With -m option, treat arguments as glob patterns. * /* With -m option, treat arguments as glob patterns. *
* "unhash -m '*'" is legal, but not recommended. */ * "unhash -m '*'" is legal, but not recommended. */
if (OPT_ISSET(ops,'m')) { if (OPT_ISSET(ops,'m')) {

View file

@ -59,6 +59,9 @@
#define BIN_ENABLE 25 #define BIN_ENABLE 25
#define BIN_PRINTF 26 #define BIN_PRINTF 26
#define BIN_COMMAND 27 #define BIN_COMMAND 27
#define BIN_UNHASH 28
#define BIN_UNALIAS 29
#define BIN_UNFUNCTION 30
/* These currently depend on being 0 and 1. */ /* These currently depend on being 0 and 1. */
#define BIN_SETOPT 0 #define BIN_SETOPT 0

View file

@ -83,3 +83,13 @@
> a string S > a string S
*>*5*echo S a string S " *>*5*echo S a string S "
# Note there is a trailing space on the "> a string S " line # Note there is a trailing space on the "> a string S " line
(
unalias -a
alias
)
0:unalias -a
alias -s foo=print
unalias -as
0:unalias -as