From: "Juergen A. Erhard" <jae@laden.ilk.de>
To: zsh-workers@math.gatech.edu
Subject: whence following symlinks
Date: Thu, 10 Apr 1997 20:04:30 -0100 [thread overview]
Message-ID: <199704102104.UAA00359@Laden2.ilk.de> (raw)
-----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@laden.ilk.de |
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-----
next reply other threads:[~1997-04-10 18:14 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-04-10 21:04 Juergen A. Erhard [this message]
1997-04-11 14:10 ` Zefram
1997-04-21 14:34 ` Juergen A. Erhard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199704102104.UAA00359@Laden2.ilk.de \
--to=jae@laden.ilk.de \
--cc=zsh-workers@math.gatech.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).