* listing all executables by prefix?
@ 2002-04-15 17:31 Sven Guckes
2002-04-15 17:56 ` Bart Schaefer
0 siblings, 1 reply; 6+ messages in thread
From: Sven Guckes @ 2002-04-15 17:31 UTC (permalink / raw)
To: ZShell Users
Hi!
Listing an executable is easy with
ls -l =program
But can the same be done when you
only have a prefix of the command?
ls -l =prefix
Ideas?
This is for listing all those
mutt* vim* and zsh*, of course. :-)
Sven
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: listing all executables by prefix?
2002-04-15 17:31 listing all executables by prefix? Sven Guckes
@ 2002-04-15 17:56 ` Bart Schaefer
2002-04-15 18:16 ` Peter Stephenson
2002-04-15 19:43 ` listing all executables by prefix - solution! Sven Guckes
0 siblings, 2 replies; 6+ messages in thread
From: Bart Schaefer @ 2002-04-15 17:56 UTC (permalink / raw)
To: Sven Guckes, zsh-users
ls -l ${(@)$(hash -m prefix\*)#*=}
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: listing all executables by prefix?
2002-04-15 17:56 ` Bart Schaefer
@ 2002-04-15 18:16 ` Peter Stephenson
2002-04-15 19:43 ` listing all executables by prefix - solution! Sven Guckes
1 sibling, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2002-04-15 18:16 UTC (permalink / raw)
To: Zsh users list
"Bart Schaefer" wrote:
>
> ls -l ${(@)$(hash -m prefix\*)#*=}
I think you have to be a bit careful that the hash database is set up;
it isn't immediately after zsh -f or a rehash. I don't think you lose
much by using
ls -l "${(@f)$(whence -pm prefix\*)}"
instead. (Of course you really need to check the expansion isn't going
to be empty first.)
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: listing all executables by prefix - solution!
2002-04-15 17:56 ` Bart Schaefer
2002-04-15 18:16 ` Peter Stephenson
@ 2002-04-15 19:43 ` Sven Guckes
2002-04-16 12:03 ` Dan Kenigsberg
1 sibling, 1 reply; 6+ messages in thread
From: Sven Guckes @ 2002-04-15 19:43 UTC (permalink / raw)
To: zsh-users
* Bart Schaefer <schaefer@brasslantern.com> [2002-04-15 17:56]:
> ls -l ${(@)$(hash -m prefix\*)#*=}
thanks, Bart! :-)
but there must be something about
what Peter Stephenson said in his mail,
because his version works always. so
now I'm using "whence" in my function:
# function _lap { for i in ${(@)$(hash -m $1\*)#*=}; do ls -l $i; done}
function _lap { for i in "${(@f)$(whence -pm $1\*)}"; do ls -l $i; done}
zsh> _lap zsh
-rwxr-xr-x 2 guckes emailer 456536 Oct 29 03:32 /home/sguckes/bin/zsh-4.0.4
-rwxr-xr-x 1 root root 405212 Jun 23 1999 /import/local/bin/zsh-3.0.5
-rwxr-xr-x 3 root other 492576 Mar 24 2001 /import/local/bin/zsh-3.0.6
-rwxr-xr-x 3 root other 492576 Mar 24 2001 /import/local/bin/zsh-3.0.8
-rwxr-xr-x 2 guckes emailer 456536 Oct 29 03:32 /home/sguckes/bin/zsh
cool! :-)
Sven [trying to figure out how it all works]
--
"it must be wonderful - i
dont understand it at all!" ;-)
vim: nowrap
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: listing all executables by prefix - solution!
2002-04-15 19:43 ` listing all executables by prefix - solution! Sven Guckes
@ 2002-04-16 12:03 ` Dan Kenigsberg
2002-04-16 13:40 ` Peter Stephenson
0 siblings, 1 reply; 6+ messages in thread
From: Dan Kenigsberg @ 2002-04-16 12:03 UTC (permalink / raw)
To: Sven Guckes; +Cc: zsh-users
>
> * Bart Schaefer <schaefer@brasslantern.com> [2002-04-15 17:56]:
> > ls -l ${(@)$(hash -m prefix\*)#*=}
>
> thanks, Bart! :-)
>
> but there must be something about
> what Peter Stephenson said in his mail,
> because his version works always. so
> now I'm using "whence" in my function:
>
> # function _lap { for i in ${(@)$(hash -m $1\*)#*=}; do ls -l $i; done}
> function _lap { for i in "${(@f)$(whence -pm $1\*)}"; do ls -l $i; done}
>
> zsh> _lap zsh
> -rwxr-xr-x 2 guckes emailer 456536 Oct 29 03:32 /home/sguckes/bin/zsh-4.0.4
> -rwxr-xr-x 1 root root 405212 Jun 23 1999 /import/local/bin/zsh-3.0.5
> -rwxr-xr-x 3 root other 492576 Mar 24 2001 /import/local/bin/zsh-3.0.6
> -rwxr-xr-x 3 root other 492576 Mar 24 2001 /import/local/bin/zsh-3.0.8
> -rwxr-xr-x 2 guckes emailer 456536 Oct 29 03:32 /home/sguckes/bin/zsh
>
> cool! :-)
>
and something like:
function _lap { tmp="${(@f)$(whence -pm $1\*)}"; [[ ! -z $tmp ]] && ls -l ${=tmp} }
will produce fewer processes on the way.
Dan.
P.S. I wouldn't know why
function _lap { tmp=$(whence -pm $1\*); [[ ! -z $tmp ]] && ls -l ${=tmp} }
is not as good, but I'm such a shameless newbie, so it is not that surprising.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: listing all executables by prefix - solution!
2002-04-16 12:03 ` Dan Kenigsberg
@ 2002-04-16 13:40 ` Peter Stephenson
0 siblings, 0 replies; 6+ messages in thread
From: Peter Stephenson @ 2002-04-16 13:40 UTC (permalink / raw)
To: Zsh users list
Dan Kenigsberg wrote:
> and something like:
>
> function _lap { tmp="${(@f)$(whence -pm $1\*)}"; [[ ! -z $tmp ]] &&
> ls -l ${=tmp} }
>
> will produce fewer processes on the way.
Except... see below.
> P.S. I wouldn't know why
>
> function _lap { tmp=$(whence -pm $1\*); [[ ! -z $tmp ]] && ls -l ${=tmp} }
>
> is not as good, but I'm such a shameless newbie, so it is not that surprising
> .
It's not obvious at first sight. The problem here (and above) is with
spaces. Both ${=...} and normal $(...) split words on spaces. So if
you have directories with names like `Program Files' the filename will
be split at that point. The "${(@f)...}" stuff makes sure you get the
`whence output', including newlines, verbatim and then splits on the
newlines. Of course, if you have newlines in your filenames your are
totally screwed, but at least the GUI-masqeurading-as-an-OS I alluded to
before isn't in the habit of using them.
Hence your solution is better written using an array:
function _lap {
local tmp
tmp=("${(@f)$(whence -pm $1\*)}")
(( $#tmp )) && ls -l $tmp
}
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK Tel: +44 (0)1223 392070
**********************************************************************
The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential
and/or privileged material.
Any review, retransmission, dissemination or other use of, or
taking of any action in reliance upon, this information by
persons or entities other than the intended recipient is
prohibited.
If you received this in error, please contact the sender and
delete the material from any computer.
**********************************************************************
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-04-16 13:41 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-15 17:31 listing all executables by prefix? Sven Guckes
2002-04-15 17:56 ` Bart Schaefer
2002-04-15 18:16 ` Peter Stephenson
2002-04-15 19:43 ` listing all executables by prefix - solution! Sven Guckes
2002-04-16 12:03 ` Dan Kenigsberg
2002-04-16 13:40 ` Peter Stephenson
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).