* Is there a kind of function factory in zsh?
@ 2010-06-08 15:26 Leander Jedamus
2010-06-08 15:34 ` Mikael Magnusson
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Leander Jedamus @ 2010-06-08 15:26 UTC (permalink / raw)
To: zsh-users
Hi!
I wonder if I could use a pattern for creating fucntions, that nearly
look the same.
Background is I have to write a function for ssh, telnet, su, bash, zsh,
tcsh and so on that all look like (for example for the ssh command):
ssh()
{
set_title "ssh $@"
{
command ssh "$@"
} always {
cd .
}
};# ssh()
How can I avoid writing all that code again and again?
Thanks in advance
Leander Jedamus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Is there a kind of function factory in zsh?
2010-06-08 15:26 Is there a kind of function factory in zsh? Leander Jedamus
@ 2010-06-08 15:34 ` Mikael Magnusson
2010-06-08 15:37 ` Daniel Friesel
2010-06-08 16:00 ` Alexey I. Froloff
2 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2010-06-08 15:34 UTC (permalink / raw)
To: Leander Jedamus; +Cc: zsh-users
On 8 June 2010 17:26, Leander Jedamus <ljedamus@googlemail.com> wrote:
> Hi!
>
> I wonder if I could use a pattern for creating fucntions, that nearly look
> the same.
> Background is I have to write a function for ssh, telnet, su, bash, zsh,
> tcsh and so on that all look like (for example for the ssh command):
> ssh()
> {
> set_title "ssh $@"
> {
> command ssh "$@"
> } always {
> cd .
> }
> };# ssh()
> How can I avoid writing all that code again and again?
>
> Thanks in advance
> Leander Jedamus
>
ssh bash bing foo bar baz()
{
echo $0
}
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Is there a kind of function factory in zsh?
2010-06-08 15:26 Is there a kind of function factory in zsh? Leander Jedamus
2010-06-08 15:34 ` Mikael Magnusson
@ 2010-06-08 15:37 ` Daniel Friesel
2010-06-08 16:00 ` Alexey I. Froloff
2 siblings, 0 replies; 4+ messages in thread
From: Daniel Friesel @ 2010-06-08 15:37 UTC (permalink / raw)
To: zsh-users; +Cc: Leander Jedamus
[-- Attachment #1: Type: text/plain, Size: 325 bytes --]
You could build a function factory with eval, but in this case there is an
even easier possibility:
function ssh telnet su bash zsh tcsh {
set_title "$0 $@"
{
command $0 "$@"
} always {
cd .
}
}
This defines a function for ssh, telnet etc., $0 always evaluates to the name
by which the function was called.
--derf
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Is there a kind of function factory in zsh?
2010-06-08 15:26 Is there a kind of function factory in zsh? Leander Jedamus
2010-06-08 15:34 ` Mikael Magnusson
2010-06-08 15:37 ` Daniel Friesel
@ 2010-06-08 16:00 ` Alexey I. Froloff
2 siblings, 0 replies; 4+ messages in thread
From: Alexey I. Froloff @ 2010-06-08 16:00 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 279 bytes --]
On Tue, Jun 08, 2010 at 05:26:38PM +0200, Leander Jedamus wrote:
> How can I avoid writing all that code again and again?
Try precmd() function. man zshall -> SPECIAL FUNCTIONS -> Hook
Functions.
--
Regards, --
Sir Raorn. --- http://thousandsofhate.blogspot.com/
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2010-06-08 16:00 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-08 15:26 Is there a kind of function factory in zsh? Leander Jedamus
2010-06-08 15:34 ` Mikael Magnusson
2010-06-08 15:37 ` Daniel Friesel
2010-06-08 16:00 ` Alexey I. Froloff
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).