Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
-M option for hash
- X-seq: zsh-workers 722
- From: Zefram <A.Main@xxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx (Z Shell workers mailing list)
- Subject: -M option for hash
- Date: Mon, 8 Jan 1996 12:03:34 +0000 (GMT)
-----BEGIN PGP SIGNED MESSAGE-----
This patch adds the -M option to the hash builtin. Note that if a hash
table element name contains '=', then it's not possible to generate a
correct hash command, so the command that `ought' to work is output
preceded by "# ". This isn't an issue with any other command that can
meaningfully acquire a -M option. Output looks like:
hash X=/usr/X11/bin/X
hash '['=/bin/'['
# hash 'x=y'=/home/luser/bin/'x=y'
hash xterm=/usr/X11/bin/xterm
Note that only the last section of the pathname is quoted in these
cases; the directory is stored separately, and so must be quoted
separately. I don't think it's worth messing about with temporary
buffers just to have the whole pathname quoted together. The commands
output are correct.
The man page patch is actually a general revamp of the entry, taking
into account the fact that the named directories are now in a hash
table. The patch actually relies somewhat upon my recent patch that
made the named directory table a hash table.
-zefram
*** 1.6 1996/01/08 10:01:52
--- Src/builtin.c 1996/01/08 11:04:21
***************
*** 3268,3273 ****
--- 3268,3274 ----
Comp com;
Asgment asg;
int returnval = 0;
+ int printflags = 0;
HashTable ht = ops['d'] ? nameddirtab : cmdnamtab;
void (*scrap) _((void)) = ops['d'] ? newnameddirtable : newcmdnamtable;
void (*fill) _((void)) = ops['d'] ? addusernames : fullhash;
***************
*** 3290,3298 ****
return 0;
}
/* Given no arguments, display current hash table. */
if (!*argv) {
! scanhashtable(ht, 1, 0, 0, ht->printnode, 0);
return 0;
}
--- 3291,3302 ----
return 0;
}
+ if(ops['M'])
+ printflags |= PRINT_LIST;
+
/* Given no arguments, display current hash table. */
if (!*argv) {
! scanhashtable(ht, 1, 0, 0, ht->printnode, printflags);
return 0;
}
***************
*** 3316,3322 ****
tokenize(*argv); /* expand */
if ((com = parsereg(*argv))) {
/* display matching hash table elements */
! scanmatchtable(ht, com, 0, 0, ht->printnode, 0);
} else {
untokenize(*argv);
zerrnam(name, "bad pattern : %s", *argv, 0);
--- 3320,3326 ----
tokenize(*argv); /* expand */
if ((com = parsereg(*argv))) {
/* display matching hash table elements */
! scanmatchtable(ht, com, 0, 0, ht->printnode, printflags);
} else {
untokenize(*argv);
zerrnam(name, "bad pattern : %s", *argv, 0);
*** 1.3 1996/01/07 02:09:24
--- Src/hashtable.c 1996/01/08 11:19:30
***************
*** 560,569 ****
return;
}
if (cn->flags & HASHED)
! printf("%s=%s\n", cn->nam, cn->u.cmd);
! else
! printf("%s=%s/%s\n", cn->nam, *(cn->u.name), cn->nam);
}
/***************************************/
--- 560,584 ----
return;
}
+ if (printflags & PRINT_LIST) {
+ /* it's not possible to explicitly hash command names containing = */
+ if(strchr(cn->nam, '='))
+ printf("# ");
+ printf("hash ");
+ if(cn->nam[0] == '-')
+ printf("-- ");
+ }
+
+ printquoted(cn->nam);
+ putchar('=');
if (cn->flags & HASHED)
! printquoted(cn->u.cmd);
! else {
! printquoted(*(cn->u.name));
! putchar('/');
! printquoted(cn->nam);
! }
! putchar('\n');
}
/***************************************/
***************
*** 1209,1214 ****
--- 1224,1238 ----
printquoted(nd->nam);
putchar('\n');
return;
+ }
+
+ if (printflags & PRINT_LIST) {
+ /* it's not possible to explicitly hash directory names containing = */
+ if(strchr(nd->nam, '='))
+ printf("# ");
+ printf("hash -d ");
+ if(nd->nam[0] == '-')
+ printf("-- ");
}
printquoted(nd->nam);
*** 1.4 1996/01/08 10:01:52
--- Src/hashtable.h 1996/01/08 10:55:17
***************
*** 267,273 ****
{NULL, "functions", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "mtu", NULL},
{NULL, "getln", 0, bin_read, 0, -1, 0, "ecnAlE", "zr"},
{NULL, "getopts", 0, bin_getopts, 2, -1, 0, NULL, NULL},
! {NULL, "hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "dfmr", NULL},
#ifdef ZSH_HASH_DEBUG
{NULL, "hashinfo", 0, bin_hashinfo, 0, 0, 0, NULL, NULL},
--- 267,273 ----
{NULL, "functions", BINF_TYPEOPTS, bin_functions, 0, -1, 0, "mtu", NULL},
{NULL, "getln", 0, bin_read, 0, -1, 0, "ecnAlE", "zr"},
{NULL, "getopts", 0, bin_getopts, 2, -1, 0, NULL, NULL},
! {NULL, "hash", BINF_MAGICEQUALS, bin_hash, 0, -1, 0, "drfmM", NULL},
#ifdef ZSH_HASH_DEBUG
{NULL, "hashinfo", 0, bin_hashinfo, 0, 0, 0, NULL, NULL},
*** 1.4 1996/01/08 10:01:52
--- Doc/zshbuiltins.man 1996/01/08 11:45:57
***************
*** 408,458 ****
message. The exit status is nonzero when there are no more options.
.RE
.TP
! \fBhash\fP [ \-\fBdfmr\fP ] [ \fIname\fP[=\fIvalue\fP] ] ...
.RS
! With no arguments or options, \fBhash\fP will list the entire command
! hash table.
.PP
The \-\fBm\fP option causes the arguments to be taken as patterns
(they should be quoted) and the elements of the command hash table
! matching these patterns are printed.
.PP
- The \-\fBr\fP option causes the command hash table to be thrown out and
- restarted. The \-\fBf\fP option causes the entire path to be searched,
- and all the commands found are added to the hash table. These options
- cannot be used with any arguments.
- .PP
For each \fIname\fP with a corresponding \fIvalue\fP, put \fIname\fP in
! the command hash table, associating it with the pathname \fIvalue\fP.
! Whenever \fIname\fP is used as a command argument, the shell will try
! to execute the file given by \fIvalue\fP. For each \fIname\fP with no
! corresponding \fIvalue\fP, search for \fIname\fP in the path, and add
! it to the command hash table, and associating it with the discovered
! path, if it is found.
! .PP
! Adding the \-\fBd\fP option causes \fBhash\fP to act on the named
! directory table instead of the command hash table. The remaing discussion
! of \fBhash\fP will assume that the \-\fBd\fP is given.
! .PP
! If invoked without any arguments, and without any other options,
! \fBhash -d\fP lists the entire named directory table.
! .PP
! The \-\fBm\fP option causes the arguments to be taken as patterns
! (they should be quoted) and the elements of the named directory table
! matching these patterns are printed.
! .PP
! The \-\fBr\fP option causes the named directory table to be thrown out
! and restarted so that it only contains `~'. The \-\fBf\fP option causes
! all usernames to be added to the named directory table. There options
! cannot be used with any arguments.
! .PP
! For each \fIname\fP with a
! corresponding \fIvalue\fP, put \fIname\fP in the named directory table.
! The directory name \fIname\fP is then associated with the specified path
! \fIvalue\fP, so that \fIvalue\fP may be referred to as `~\fIname\fP'.
! For each \fIname\fP with no corresponding \fIvalue\fP, search for as a
! username and as a parameter. If it is found, it is added to the named
! directory hash table.
.RE
.TP
\fBhistory\fP [ \-\fBnrdDfEim\fP ] [ \fIfirst\fP [ \fIlast\fP ] ]
--- 408,457 ----
message. The exit status is nonzero when there are no more options.
.RE
.TP
! \fBhash\fP [ \-\fBdrfmM\fP ] [ \fIname\fP[=\fIvalue\fP] ] ...
.RS
! \fBhash\fP can be used to directly modify the contents of the command
! hash table, and the named directory hash table. Normally one would
! add to these tables by modifying one's
! .I PATH
! (for the command hash table) or by creating appropriate shell parameters
! (for the named directory hash table).
! The choice of hash table to work on is determined by the \-\fBd\fP option;
! without the option the command hash table is used, and with the option the
! named directory hash table is used.
! .PP
! The \-\fBr\fP option causes the selected hash table to be blanked.
! It will be subsequently rebuilt in the normal fashion.
! The \-\fBf\fP option causes the selected hash table to be fully
! rebuilt immediately; for the command hash table this hashes
! all the absolute directories in the
! .IR PATH ,
! and for the named directory hash table this adds all users' home directories.
! These two options cannot be used with any arguments.
! .PP
! Given no arguments, the selected hash table will be listed in full.
! The \-\fBM\fP option causes this listing to be in the form of
! .B hash
! commands that will recreate the current state of the hash table.
.PP
The \-\fBm\fP option causes the arguments to be taken as patterns
(they should be quoted) and the elements of the command hash table
! matching these patterns are listed. This is the only way to display
! a limited selection of hash table elements.
.PP
For each \fIname\fP with a corresponding \fIvalue\fP, put \fIname\fP in
! the selected hash table, associating it with the pathname \fIvalue\fP.
! In the command hash table, this means that
! whenever \fIname\fP is used as a command argument, the shell will try
! to execute the file given by \fIvalue\fP.
! In the named directory hash table, this means
! that \fIvalue\fP may be referred to as `~\fIname\fP'.
! .PP
! For each \fIname\fP with no
! corresponding \fIvalue\fP, attempt to add \fIname\fP to the hash table,
! checking what the appropriate \fIvalue\fP is in the normal manner for
! that hash table. If an appropriate \fIvalue\fP can't be found, then
! the hash table will be unchanged.
.RE
.TP
\fBhistory\fP [ \-\fBnrdDfEim\fP ] [ \fIfirst\fP [ \fIlast\fP ] ]
-----BEGIN PGP SIGNATURE-----
Version: 2.6.i
iQCVAgUBMPEH8nD/+HJTpU/hAQFIDgQAgUxLM+weem6cwWVnXIGtNzPuj3pi4Mym
hK1Wnc5d7TtzkAEBPTXPC4ACHKJIEdhMJ7UDC09S09dkosi0dMVPZPewHpAbPfWh
8laz0ckTC0qiN7Rd8F5CR5zpY8tImWFt7xZ0SQx65qIDeJeMoQ85ORpMF4zOmuF+
+HYp1T4EI9M=
=Xo6Y
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author