* A conditional test to see whether a function is loaded?
@ 2007-06-09 12:31 William Scott
2007-06-09 12:45 ` Frank Terbeck
0 siblings, 1 reply; 8+ messages in thread
From: William Scott @ 2007-06-09 12:31 UTC (permalink / raw)
To: zsh-users
Hi everyone:
I want to write a shell script that (among other things) tests to see
if a function foo is loaded.
Is there something analogous to [[ -x $(which foo) ]] that would
test specifically for a loaded function, or an autoloadable function,
rather than an executable file?
Thanks.
Bill
William G. Scott
contact info: http://chemistry.ucsc.edu/~wgscott
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A conditional test to see whether a function is loaded?
2007-06-09 12:31 A conditional test to see whether a function is loaded? William Scott
@ 2007-06-09 12:45 ` Frank Terbeck
2007-06-09 14:29 ` William Scott
0 siblings, 1 reply; 8+ messages in thread
From: Frank Terbeck @ 2007-06-09 12:45 UTC (permalink / raw)
To: zsh-users
William Scott <wgscott@chemistry.ucsc.edu>:
> Hi everyone:
>
> I want to write a shell script that (among other things) tests to see if a
> function foo is loaded.
>
> Is there something analogous to [[ -x $(which foo) ]] that would test
> specifically for a loaded function, or an autoloadable function, rather
> than an executable file?
Try this:
[snip]
zsh% [[ -n ${functions[promptinit]} ]] && echo yay || echo nay
nay
zsh% autoload -U promptinit
zsh% [[ -n ${functions[promptinit]} ]] && echo yay || echo nay
yay
[snap]
Regards, Frank
--
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
-- RFC 1925
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A conditional test to see whether a function is loaded?
2007-06-09 12:45 ` Frank Terbeck
@ 2007-06-09 14:29 ` William Scott
2007-06-09 15:16 ` fREW
0 siblings, 1 reply; 8+ messages in thread
From: William Scott @ 2007-06-09 14:29 UTC (permalink / raw)
To: zsh-users
Thanks!
Frank Terbeck wrote:
> zsh% [[ -n ${functions[promptinit]} ]] && echo yay || echo nay
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A conditional test to see whether a function is loaded?
2007-06-09 14:29 ` William Scott
@ 2007-06-09 15:16 ` fREW
2007-06-09 15:23 ` Frank Terbeck
2007-06-09 19:44 ` Peter Stephenson
0 siblings, 2 replies; 8+ messages in thread
From: fREW @ 2007-06-09 15:16 UTC (permalink / raw)
To: William Scott; +Cc: zsh-users
On 6/9/07, William Scott <wgscott@chemistry.ucsc.edu> wrote:
> Thanks!
>
> Frank Terbeck wrote:
>
> > zsh% [[ -n ${functions[promptinit]} ]] && echo yay || echo nay
>
I have a similar question. Is there a shorter, more zsh-y way to do:
[[ -x `which aptitude` ]]
Obviously replace aptitude with any program. I tried [[ -x =aptitude
]] but that gives error messages if it doesn't exist.
--
-fREW
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A conditional test to see whether a function is loaded?
2007-06-09 15:16 ` fREW
@ 2007-06-09 15:23 ` Frank Terbeck
2007-06-09 19:44 ` Peter Stephenson
1 sibling, 0 replies; 8+ messages in thread
From: Frank Terbeck @ 2007-06-09 15:23 UTC (permalink / raw)
To: zsh-users
fREW <frioux@gmail.com>:
> On 6/9/07, William Scott <wgscott@chemistry.ucsc.edu> wrote:
>> Frank Terbeck wrote:
>>
>> > zsh% [[ -n ${functions[promptinit]} ]] && echo yay || echo nay
>>
>
> I have a similar question. Is there a shorter, more zsh-y way to do:
> [[ -x `which aptitude` ]]
I'd write [[ -x $(which aptitude) ]], which means the same, but looks
better, IMHO. :-)
> Obviously replace aptitude with any program. I tried [[ -x =aptitude
> ]] but that gives error messages if it doesn't exist.
The reason this fails is, that the shell tries to expand =aptitude,
but if aptitude is not there, that fails, thus the error message.
Regards, Frank
--
In protocol design, perfection has been reached not when there is
nothing left to add, but when there is nothing left to take away.
-- RFC 1925
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: A conditional test to see whether a function is loaded?
2007-06-09 15:16 ` fREW
2007-06-09 15:23 ` Frank Terbeck
@ 2007-06-09 19:44 ` Peter Stephenson
1 sibling, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2007-06-09 19:44 UTC (permalink / raw)
To: zsh-users
fREW wrote:
> On 6/9/07, William Scott <wgscott@chemistry.ucsc.edu> wrote:
> > Thanks!
> >
> > Frank Terbeck wrote:
> >
> > > zsh% [[ -n ${functions[promptinit]} ]] && echo yay || echo nay
> >
>
> I have a similar question. Is there a shorter, more zsh-y way to do:
> [[ -x `which aptitude` ]]
Basically the same answer; you need to look at the description of the
zsh/parameter module in the zshmodules manual page for this kind of
thing. These are the same parameters the completion system uses:
[[ -x ${commands[aptitude]} ]] && echo yay || echo nay
> Obviously replace aptitude with any program. I tried [[ -x =aptitude
> ]] but that gives error messages if it doesn't exist.
fn() {
emulate -L zsh
setopt nonomatch
[[ -x =aptitude ]]
}
will fix that problem. You can use a parameter expression; parameter
expansion occurs before =-expansion (unless you have the bad taste
to set SH_FILE_EXPANSION, but "emulate" takes care of that in this case):
fn() {
emulate -L zsh
setopt nonomatch
[[ -x =$1 ]]
}
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <frioux@gmail.com>]
* Time Modifiers
@ 2007-06-01 22:10 ` fREW
2007-06-02 16:37 ` Peter Stephenson
0 siblings, 1 reply; 8+ messages in thread
From: fREW @ 2007-06-01 22:10 UTC (permalink / raw)
To: Zsh users list
Hello amigos,
Can anyone tell me exactly how the edges work on the time modifiers?
Example: When I say ls *(m1) does it give me everything from the past
24 hours, or is it everything from June 1st? Similarly, if I do ls
*(m-1) is the edge the beginning of of June 1st or is it 24 hours ago?
Same with hours. Is ls *(mh1) start at 4 pm, or is it just whenever
60 minutes ago is?
Thanks much!
--
-fREW
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Time Modifiers
2007-06-01 22:10 ` Time Modifiers fREW
@ 2007-06-02 16:37 ` Peter Stephenson
0 siblings, 0 replies; 8+ messages in thread
From: Peter Stephenson @ 2007-06-02 16:37 UTC (permalink / raw)
To: Zsh users list
fREW wrote:
> Hello amigos,
>
> Can anyone tell me exactly how the edges work on the time modifiers?
>
> Example: When I say ls *(m1) does it give me everything from the past
> 24 hours, or is it everything from June 1st? Similarly, if I do ls
> *(m-1) is the edge the beginning of of June 1st or is it 24 hours ago?
> Same with hours. Is ls *(mh1) start at 4 pm, or is it just whenever
> 60 minutes ago is?
It's the given period before right now; there's no rounding except to
the nearest second, so it's the first answer in the first case, and the
second answer in the second case.
If you want to specify dates and times and are up to date with version
4.3.4, you can use the "age" function as a modifer:
autoload -U age
print *(e:age today now:) # files modified today
print *(e-age 17:00 now-) # files modified since 5 pm
print *(e-age yesterday,17:00 now-) # ... since 5 o'clock yesterday
print *(e-age 2006/12/25 today-) # ... from last Christmas before today
print *(e-age 1970/01/01 yesterday-) # ... before yesterday
and so on. Note that "today" is a specific time, i.e. midnight last
night.
--
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-06-10 1:14 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-09 12:31 A conditional test to see whether a function is loaded? William Scott
2007-06-09 12:45 ` Frank Terbeck
2007-06-09 14:29 ` William Scott
2007-06-09 15:16 ` fREW
2007-06-09 15:23 ` Frank Terbeck
2007-06-09 19:44 ` Peter Stephenson
[not found] <frioux@gmail.com>
2007-06-01 22:10 ` Time Modifiers fREW
2007-06-02 16:37 ` 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).