zsh-workers
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-workers@zsh.org
Cc: Emanuel Berg <embe8573@student.uu.se>
Subject: Re: multi-alias syntax
Date: Wed, 24 Jun 2015 18:42:01 -0700	[thread overview]
Message-ID: <150624184201.ZM19069@torch.brasslantern.com> (raw)
In-Reply-To: <87fv5gk8m8.fsf@nl106-137-147.student.uu.se>

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.


  reply	other threads:[~2015-06-25  1:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-24 17:16 Emanuel Berg
2015-06-24 18:34 ` Bart Schaefer
2015-06-24 23:08   ` Emanuel Berg
2015-06-25  1:42     ` Bart Schaefer [this message]
2015-06-25  1:55       ` Emanuel Berg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=150624184201.ZM19069@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=embe8573@student.uu.se \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).