[gobolinux-users] which

Hisham hisham.hm at gmail.com
Thu Mar 27 08:45:24 NZDT 2008


On Tue, Mar 25, 2008 at 1:03 AM, Nick Matteo <kundor at kundor.org> wrote:
> The "which" provided by Scripts doesn't have the standard "-a" option.
>   I've had scripts complain about this (and even fail) a time or two.
>  Also, I find it annoying that "which info" lies to me about what
>  "info" runs if it is an alias.
>
>  To deal with these issues, perhaps it would have been easy enough to
>  have Scripts' which do a "-a" and alias which=whence for interactive
>  use.  But instead I wrote a big which-function. ;-)
>
>  By placing this function in /etc/zshenv, it's used even for scripts
>  and such.  (It needs to be a function, not a script, to be able to
>  access aliases etc. in interactive mode.)  Then I replace the "which"
>  script in the path with a simple script like so:
>
>  #!/bin/zsh
>  which -f $@
>
>  To have my script used by other programs appropriately.
>  If you'd like to do the same, you can get the zshenv at
>  http://kundor.org/gobostuff/zshenv .  If you place this file in
>  /Programs/ZSH/Settings,
>  then
>  cd /Programs/ZSH/Settings
>  zcompile zshenv
>  (You may need root for that)
>  SymlinkProgram ZSH
>
>  It will create a precompiled version of the function to speed up shell
>  loads.  (You can also "zcompile zshrc" for the same purpose.)
>  Then put that two-liner script in your path as "which" and you will
>  get an option-accepting, alias-reporting which ;-)
>
>  Options taken are -h/--help, -a/--all (reports multiple results from path),
>  -p/--path-only (Normally, an alias, builtin, or function is reported
>  as e.g. "aliased to /Programs/Foo/1/...".  This strips everything but
>  the path so that "file `which -p foo`" and similar constructs will
>  work properly),
>  -f/--file-only (This doesn't check aliases, builtins, or functions,
>  reverting to checking for executables only.)

Cool -- I installed it here in my machine to test this for a while.
Results look interesting already. :)

-- Hisham


More information about the gobolinux-users mailing list