Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
whence following symlinks
- X-seq: zsh-workers 3067
- From: "Juergen A. Erhard" <jae@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx
- Subject: whence following symlinks
- Date: Thu, 10 Apr 1997 20:04:30 -0100
-----BEGIN PGP SIGNED MESSAGE-----
My first zsh hack.
Ever did a 'which sh', and wondered whether '/bin/sh' was REALLY just
'/bin/sh' or not, rather, '/bin/bash'... honest, how many systems do
YOU know that have a '/bin/sh'? Is your's NOT linked to '/bin/zsh'?
Shame on you ;-)
Okay. Now with this patch, 'which -s' follows symlinks and prints
them, separated by ' -> ', after the first path found.
Unfortunately, 'whence -ms' doesn't work as expected, because '-m'
jumps to a different code section, and that code doesn't care for
'-s'.
To get 'whence -ms', do something like this
whence -m '*sh' | sed 's/.*/whence -s
This at least works for me.
Another thing missing is checking for hard links... but that is a lot
more complicated, next to impossible. At least we might check whether
the path found has more than one name (hard links > 1), to give the
user an idea that this might not be what it seems to be.
And now, here's the patch, done with 'diff -cp', relative to zsh 3.1.0.
Enjoy -- JAE
*** hashtable.h 1997/03/19 09:45:12 1.1
- --- hashtable.h 1997/03/19 10:07:07
*************** struct builtin builtins[] =
*** 338,346 ****
{NULL, "unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fm", NULL},
{NULL, "unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL},
{NULL, "wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL},
! {NULL, "whence", 0, bin_whence, 0, -1, 0, "acmpvf", NULL},
{NULL, "where", 0, bin_whence, 0, -1, 0, "pm", "ca"},
! {NULL, "which", 0, bin_whence, 0, -1, 0, "amp", "c"},
{NULL, NULL}
};
#else
- --- 338,346 ----
{NULL, "unset", BINF_PSPECIAL, bin_unset, 1, -1, 0, "fm", NULL},
{NULL, "unsetopt", 0, bin_setopt, 0, -1, BIN_UNSETOPT, NULL, NULL},
{NULL, "wait", 0, bin_fg, 0, -1, BIN_WAIT, NULL, NULL},
! {NULL, "whence", 0, bin_whence, 0, -1, 0, "acmpvfs", NULL},
{NULL, "where", 0, bin_whence, 0, -1, 0, "pm", "ca"},
! {NULL, "which", 0, bin_whence, 0, -1, 0, "amps", "c"},
{NULL, NULL}
};
#else
*** builtin.c 1997/03/19 07:48:38 1.1
- --- builtin.c 1997/04/09 15:09:10
***************
*** 2244,2252 ****
} else if ((cnam = findcmd(*argv))) {
/* Found external command. */
if (v && !csh)
! printf("%s is %s\n", *argv, cnam);
else
! puts(cnam);
zsfree(cnam);
} else {
/* Not found at all. */
- --- 2244,2278 ----
} else if ((cnam = findcmd(*argv))) {
/* Found external command. */
if (v && !csh)
! printf("%s is %s", *argv, cnam);
else
! fputs(cnam,stdout);
!
! /* now check symlinks if -s given */
! if (ops['s']) {
! /* temporary vars for this if */
! char *try_link;
! int chase;
!
! /* temporarily set CHASELINKS */
! chase = isset(CHASELINKS);
! dosetopt(CHASELINKS, 1, 0);
!
! /* get possible link */
! try_link = xsymlink(cnam);
!
! /* if it is one (different from cnam), print it */
! if (strcmp(cnam,try_link)!=0)
! printf(" -> %s",try_link);
!
! /* revert setting of CHASELINKS */
! dosetopt(CHASELINKS, chase, 0);
!
! /* throw away try_link... hope this is the right fn */
! zsfree(try_link);
! }
!
! fputc('\n',stdout);
zsfree(cnam);
} else {
/* Not found at all. */
- --
Juergen A. Erhard (that ue is actually \"u (TeX) or ü (HTML/SGML))
eMail: jae@xxxxxxxxxxxx |
snailMail: Belfortstr. 6; 76133 Karlsruhe; GERMANY | pros do it for money,
phone: +49 721 27326 | amateurs out of love.
WWW: http://members.tripod.com/~Juergen_Erhard/ (under construction!)
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv
Comment: Processed by Mailcrypt 3.4, an Emacs/PGP interface
iQEVAwUBM0u7dgIG66LugGzRAQE6uAf6AkR+eDriEOB9/zWFKwL+d2nsq/V772pL
nh2XaeqesKGIzvFN106uHIXDVj01JtbZjWQKVtPn9Alb1tkIpBGDxU0cHQ+qo1eR
uNpdeoWxwl9kbYNgZar38YI0TXm7+RvoEnIR27ADp1cplBYunOcReezCEAB7RhME
K5cMQBTP8swNrY8WCfxt/cAyKXL1PkkjLSbbn/8hEIVnrJMKcr30tWtLzgpD8SF+
veW6oOTCmmybFljODWAOS9/BRfmkqH8XV5dKdMJupvWYJDw8K3FVV7ewDUwamJfb
vxufZ6k77VOFySWCcEid3bnUsZ8/tPOkXF4M6aP7FKp0EWJZFi6AjQ==
=SHwK
-----END PGP SIGNATURE-----
Messages sorted by:
Reverse Date,
Date,
Thread,
Author