Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Determing type for command name
- X-seq: zsh-workers 4388
- From: Peter Stephenson <pws@xxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Zsh hackers list)
- Subject: Re: Determing type for command name
- Date: Wed, 16 Sep 1998 12:11:45 +0200
- In-reply-to: "Nik Gervae"'s message of "Wed, 26 Aug 1998 13:49:06 MST." <35E47493.E7B6C32A@xxxxxxxxx>
Nik Gervae wrote:
> I find myself needing to selectively undefine aliases or functions
> in different situations. The whence -v command, which gives a verbose,
> English description, will suffice, but doesn't seem robust enough
> to me. More specifically, there's no guarantee that the descriptions
> won't change without warning between releases. Can we have a new
> flag on whence that will cause it to print a single, well-defined,
> and documented word for each of the possibilities?
I think that's an excellent idea. whence -w (or type -w, since one
would intuitively expect that to work) now does just that. On the
other hand, you can probably solve the problem I presume you have by
testing the return statuses of `alias foo >&/dev/null' and `functions foo
>&/dev/null'.
*** Doc/Zsh/builtins.yo.word Thu Jun 12 14:36:06 1997
--- Doc/Zsh/builtins.yo Wed Sep 16 11:46:56 1998
***************
*** 848,854 ****
terminal is frozen or not.
)
findex(type)
! item(tt(type) [ tt(-fpams) ] var(name) ...)(
Equivalent to tt(whence -v).
)
findex(typeset)
--- 848,854 ----
terminal is frozen or not.
)
findex(type)
! item(tt(type) [ tt(-wfpams) ] var(name) ...)(
Equivalent to tt(whence -v).
)
findex(typeset)
***************
*** 1026,1032 ****
The exit status from this command is that of the job waited for.
)
findex(whence)
! item(tt(whence) [ tt(-vcfpams) ] var(name) ...)(
For each name, indicate how it would be interpreted if used as a
command name.
--- 1026,1032 ----
The exit status from this command is that of the job waited for.
)
findex(whence)
! item(tt(whence) [ tt(-vcwfpams) ] var(name) ...)(
For each name, indicate how it would be interpreted if used as a
command name.
***************
*** 1037,1042 ****
--- 1037,1051 ----
item(tt(-c))(
Print the results in a bf(csh)-like format.
This takes precedence over tt(-v).
+ )
+ item(tt(-w))(
+ For each var(name), print `var(name)tt(:) var(word)' where var(word)
+ is one of tt(alias), tt(builtin), tt(command), tt(function),
+ tt(hashed), tt(reserved) or tt(none), according as var(name)
+ corresponds to an alias, a built-in command, an external command, a
+ shell function, a command defined with the tt(hash) builtin, a
+ reserved word, or is not recognised. This takes precedence over
+ tt(-v) and tt(-c).
)
item(tt(-f))(
Causes the contents of a shell function to be
*** Src/builtin.c.word Wed Aug 19 15:37:27 1998
--- Src/builtin.c Wed Sep 16 11:33:20 1998
***************
*** 106,112 ****
BUILTIN("times", BINF_PSPECIAL, bin_times, 0, 0, 0, NULL, NULL),
BUILTIN("trap", BINF_PSPECIAL, bin_trap, 0, -1, 0, NULL, NULL),
BUILTIN("true", 0, bin_true, 0, -1, 0, NULL, NULL),
! BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfs", "v"),
BUILTIN("typeset", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "LRUZfilrtuxm", NULL),
BUILTIN("umask", 0, bin_umask, 0, 1, 0, "S", NULL),
BUILTIN("unalias", 0, bin_unhash, 1, -1, 0, "m", "a"),
--- 106,112 ----
BUILTIN("times", BINF_PSPECIAL, bin_times, 0, 0, 0, NULL, NULL),
BUILTIN("trap", BINF_PSPECIAL, bin_trap, 0, -1, 0, NULL, NULL),
BUILTIN("true", 0, bin_true, 0, -1, 0, NULL, NULL),
! BUILTIN("type", 0, bin_whence, 0, -1, 0, "ampfsw", "v"),
BUILTIN("typeset", BINF_TYPEOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "LRUZfilrtuxm", NULL),
BUILTIN("umask", 0, bin_umask, 0, 1, 0, "S", NULL),
BUILTIN("unalias", 0, bin_unhash, 1, -1, 0, "m", "a"),
***************
*** 115,121 ****
BUILTIN("unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fm", NULL),
BUILTIN("unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL),
BUILTIN("wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL),
! BUILTIN("whence", 0, bin_whence, 0, -1, 0, "acmpvfs", NULL),
BUILTIN("where", 0, bin_whence, 0, -1, 0, "pms", "ca"),
BUILTIN("which", 0, bin_whence, 0, -1, 0, "amps", "c"),
--- 115,121 ----
BUILTIN("unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fm", NULL),
BUILTIN("unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL),
BUILTIN("wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL),
! BUILTIN("whence", 0, bin_whence, 0, -1, 0, "acmpvfsw", NULL),
BUILTIN("where", 0, bin_whence, 0, -1, 0, "pms", "ca"),
BUILTIN("which", 0, bin_whence, 0, -1, 0, "amps", "c"),
***************
*** 162,167 ****
--- 162,172 ----
{
Builtin bn = (Builtin) hn;
+ if (printflags & PRINT_WHENCE_WORD) {
+ printf("%s: builtin\n", bn->nam);
+ return;
+ }
+
if (printflags & PRINT_WHENCE_CSH) {
printf("%s: shell built-in command\n", bn->nam);
return;
***************
*** 1807,1813 ****
Comp com;
int returnval = 0;
int printflags = 0;
! int csh, all, v;
int informed;
char *cnam;
--- 1812,1818 ----
Comp com;
int returnval = 0;
int printflags = 0;
! int csh, all, v, wd;
int informed;
char *cnam;
***************
*** 1815,1822 ****
csh = ops['c'];
v = ops['v'];
all = ops['a'];
! if (ops['c'])
printflags |= PRINT_WHENCE_CSH;
else if (ops['v'])
printflags |= PRINT_WHENCE_VERBOSE;
--- 1820,1830 ----
csh = ops['c'];
v = ops['v'];
all = ops['a'];
+ wd = ops['w'];
! if (ops['w'])
! printflags |= PRINT_WHENCE_WORD;
! else if (ops['c'])
printflags |= PRINT_WHENCE_CSH;
else if (ops['v'])
printflags |= PRINT_WHENCE_VERBOSE;
***************
*** 1919,1951 ****
continue;
strcpy(z, *argv);
if (iscom(buf)) {
! if (v && !csh)
! zputs(*argv, stdout), fputs(" is ", stdout);
! zputs(buf, stdout);
! if (ops['s'])
! print_if_link(buf);
! fputc('\n', stdout);
informed = 1;
}
}
! if (!informed && (v || csh)) {
zputs(*argv, stdout);
! puts(" not found");
returnval = 1;
}
} else if ((cnam = findcmd(*argv))) {
/* Found external command. */
! if (v && !csh)
! zputs(*argv, stdout), fputs(" is ", stdout);
! zputs(cnam, stdout);
! if (ops['s'])
! print_if_link(cnam);
! fputc('\n', stdout);
zsfree(cnam);
} else {
/* Not found at all. */
! if (v || csh)
! zputs(*argv, stdout), puts(" not found");
returnval = 1;
}
}
--- 1927,1967 ----
continue;
strcpy(z, *argv);
if (iscom(buf)) {
! if (wd) {
! printf("%s: command\n", *argv);
! } else {
! if (v && !csh)
! zputs(*argv, stdout), fputs(" is ", stdout);
! zputs(buf, stdout);
! if (ops['s'])
! print_if_link(buf);
! fputc('\n', stdout);
! }
informed = 1;
}
}
! if (!informed && (wd || v || csh)) {
zputs(*argv, stdout);
! puts(wd ? ": none" : " not found");
returnval = 1;
}
} else if ((cnam = findcmd(*argv))) {
/* Found external command. */
! if (wd) {
! printf("%s: command\n", *argv);
! } else {
! if (v && !csh)
! zputs(*argv, stdout), fputs(" is ", stdout);
! zputs(cnam, stdout);
! if (ops['s'])
! print_if_link(cnam);
! fputc('\n', stdout);
! }
zsfree(cnam);
} else {
/* Not found at all. */
! if (v || csh || wd)
! zputs(*argv, stdout), puts(wd ? ": none" : " not found");
returnval = 1;
}
}
*** Src/hashtable.c.word Wed Apr 29 23:42:48 1998
--- Src/hashtable.c Wed Sep 16 11:21:00 1998
***************
*** 655,660 ****
--- 655,666 ----
{
Cmdnam cn = (Cmdnam) hn;
+ if (printflags & PRINT_WHENCE_WORD) {
+ printf("%s: %s\n", cn->nam, (cn->flags & HASHED) ?
+ "hashed" : "command");
+ return;
+ }
+
if ((printflags & PRINT_WHENCE_CSH) || (printflags & PRINT_WHENCE_SIMPLE)) {
if (cn->flags & HASHED) {
zputs(cn->u.cmd, stdout);
***************
*** 813,822 ****
return;
}
! if ((printflags & PRINT_WHENCE_VERBOSE) &&
!(printflags & PRINT_WHENCE_FUNCDEF)) {
nicezputs(f->nam, stdout);
! printf(" is a shell function\n");
return;
}
--- 819,829 ----
return;
}
! if ((printflags & (PRINT_WHENCE_VERBOSE|PRINT_WHENCE_WORD)) &&
!(printflags & PRINT_WHENCE_FUNCDEF)) {
nicezputs(f->nam, stdout);
! printf((printflags & PRINT_WHENCE_WORD) ? ": function\n" :
! " is a shell function\n");
return;
}
***************
*** 911,916 ****
--- 918,928 ----
{
Reswd rw = (Reswd) hn;
+ if (printflags & PRINT_WHENCE_WORD) {
+ printf("%s: reserved\n", rw->nam);
+ return;
+ }
+
if (printflags & PRINT_WHENCE_CSH) {
printf("%s: shell reserved word\n", rw->nam);
return;
***************
*** 996,1001 ****
--- 1008,1018 ----
if (printflags & PRINT_NAMEONLY) {
zputs(a->nam, stdout);
putchar('\n');
+ return;
+ }
+
+ if (printflags & PRINT_WHENCE_WORD) {
+ printf("%s: alias\n", a->nam);
return;
}
*** Src/zsh.h.word Thu Jul 9 12:04:44 1998
--- Src/zsh.h Wed Sep 16 11:01:53 1998
***************
*** 892,897 ****
--- 892,898 ----
#define PRINT_WHENCE_VERBOSE (1<<4)
#define PRINT_WHENCE_SIMPLE (1<<5)
#define PRINT_WHENCE_FUNCDEF (1<<6)
+ #define PRINT_WHENCE_WORD (1<<7)
/***********************************/
/* Definitions for history control */
--
Peter Stephenson <pws@xxxxxx> Tel: +39 50 844536
WWW: http://www.ifh.de/~pws/
Gruppo Teorico, Dipartimento di Fisica
Piazza Torricelli 2, 56100 Pisa, Italy
Messages sorted by:
Reverse Date,
Date,
Thread,
Author