* multi-alias syntax
@ 2015-06-24 17:16 Emanuel Berg
2015-06-24 18:34 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2015-06-24 17:16 UTC (permalink / raw)
To: zsh-workers
Is there a better way to do, e.g.
debian-version () { lsb_release -a }
for a in debian-ver version ver; do
alias $a=debian-version
done
as
alias a b c=d
doesn't set a and b to d, only c.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: multi-alias syntax
2015-06-24 17:16 multi-alias syntax Emanuel Berg
@ 2015-06-24 18:34 ` Bart Schaefer
2015-06-24 23:08 ` Emanuel Berg
0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2015-06-24 18:34 UTC (permalink / raw)
To: zsh-workers; +Cc: Emanuel Berg
On Jun 24, 7:16pm, Emanuel Berg wrote:
}
} alias a b c=d
}
} doesn't set a and b to d, only c.
This should work
alias {a,b,c}=d
unless you have the ignore_braces option set.
--
Barton E. Schaefer
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: multi-alias syntax
2015-06-24 18:34 ` Bart Schaefer
@ 2015-06-24 23:08 ` Emanuel Berg
2015-06-25 1:42 ` Bart Schaefer
0 siblings, 1 reply; 5+ messages in thread
From: Emanuel Berg @ 2015-06-24 23:08 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer <schaefer@brasslantern.com> writes:
> This should work
>
> alias {a,b,c}=d
>
> unless you have the ignore_braces option set.
That works, thank you.
I also learned I can do
debian-version debian-ver version ver () { lsb_release -a } # 1
or, as I first thought and as you helped:
# 2
debian-version () { lsb_release -a }
alias {debian-ver,version,ver}=debian-version
Anyone cares to line up the pros and cons of the two
approaches? - in terms of programming, and use.
I can already tell they are not identical as in (1)
debian-ver etc. are functions, not aliases.
I happen to use a function I wrote called 't' (for
"type") [1] in which the function approach is better
(due to the functionality of t, of course) as
$ t ver
ver: aliased to debian-version
(doesn't say a lot) vs.
$ t ver
ver () {
lsb_release -a
}
Some programmers feel all things should have one name
each and you should just memorize it. I sort of
disagree. I want long and descriptive name in the
source so I can understand it years later. But for
interactive use I want short names in many versions.
Every time I make a mistake ("zsh: command not found")
I stop to think "OK, it isn't there. But does it make
sense still?" - if it does, I add an alias.
This method will make that easier and perhaps I'll
drop the alias method completely and have multiple
function names instead, so it will be interesting to
hear if there is any fine print to either methods.
Another thing I can tell you about the multiple
function names method is that it breaks Emacs' zsh
mode as you see in this dump [2].
[1] http://user.it.uu.se/~embe8573/conf/.zsh/ide (line 45)
[2] http://user.it.uu.se/~embe8573/dumps/zsh-font-lock.png
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: multi-alias syntax
2015-06-24 23:08 ` Emanuel Berg
@ 2015-06-25 1:42 ` Bart Schaefer
2015-06-25 1:55 ` Emanuel Berg
0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2015-06-25 1:42 UTC (permalink / raw)
To: zsh-workers; +Cc: Emanuel Berg
On Jun 25, 1:08am, Emanuel Berg wrote:
}
} debian-version debian-ver version ver () { lsb_release -a } # 1
} # 2
} debian-version () { lsb_release -a }
} alias {debian-ver,version,ver}=debian-version
Or #3
alias {debian-,}{version,ver}='lsb_release -a'
} Anyone cares to line up the pros and cons of the two
} approaches? - in terms of programming, and use.
}
} I can already tell they are not identical as in (1)
} debian-ver etc. are functions, not aliases.
That's the only difference that really matters.
General differences/gotchas with using aliases is covered in FAQ
question 2.3 ( http://zsh.sourceforge.net/FAQ/zshfaq02.html#l12 ).
Specific to this example:
#1 - uses slightly more memory
- after the functions are defined, they are separate objects, so
changing one of them doesn't change the others
#2 - changing the function changes (the outcome of) all the aliases
- changing any of the aliases doesn't change the others
#3 - changing any of the aliases doesn't change the others
Of course if you're never going to change anything on the fly once
it has been defined in your startup, most of that is irrelevant.
The additional point is that aliases expand at parse time, so if you
define an alias, then load a function that refers to the alias, and
later redefine the alias, the function will continue executing the
original expansion of the alias.
Given that you said:
} I want long and descriptive name in the
} source so I can understand it years later. But for
} interactive use I want short names in many versions.
I'd probably go with #2.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: multi-alias syntax
2015-06-25 1:42 ` Bart Schaefer
@ 2015-06-25 1:55 ` Emanuel Berg
0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2015-06-25 1:55 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer <schaefer@brasslantern.com> writes:
> Given that you said ... I'd probably go with #2.
OK, thank you.
--
underground experts united
http://user.it.uu.se/~embe8573
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-06-25 2:00 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-24 17:16 multi-alias syntax Emanuel Berg
2015-06-24 18:34 ` Bart Schaefer
2015-06-24 23:08 ` Emanuel Berg
2015-06-25 1:42 ` Bart Schaefer
2015-06-25 1:55 ` Emanuel Berg
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).