Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Function or Alias - Does it matter?
- X-seq: zsh-users 19410
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh-Users List <zsh-users@xxxxxxx>
- Subject: Re: Function or Alias - Does it matter?
- Date: Wed, 19 Nov 2014 09:59:23 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1416387564; bh=NmMi3R693+GpqCAQnAmvsjCldsnr9MjGNXI1yL512oY=; h=In-reply-to:From:References:To:Subject:Date:From:Subject; b=Jln/1Vz9vi4PfFqsI8MRemGKzFF2nPJFcK/MDZgKOLoK6F8IQeIs+c/i3M2+hcg/GwJ/0ba08MDrjS+2KDAclkj36rrOg/izUsZRJj1rIVchSIR+ZZc9BJJrQmtvwMOmHlHb/38s4xksXsjhZV/ErlUJ9Ing44XsBHiFMzx2zdvx/6WfeXH/aHC3fmZ5jBwU7WjfXOqnjNqIom98zgDUNZ4Mm3qx5v4alPFTasejZN4iZNxUs2QiUMQSGqOAFf1JjXiDCWhknkdmaHdRo5xhbboWBSr4AkR3NibaEj8DnVFEryqXS3gHadfHwyDfeX+eegBlIgwIeL7JK6qfTnEEtg==
- Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=s2048; d=yahoo.co.uk; b=jtplPXjxqHS44xRMngMKtM7TcVZR5PxP3OzF3SogUjbPo0I2rlaxVSk6zEaqVhZcrA59nza8QkisEdL6AsoI2krELrBz5fs0XJ0uayv5HI/F0dU8LhNlBt2pcUwOlPUNAKeu83eMENPx6ecjItDUlnXALjobOJcemZ6hVJgldhNVw9MqfXNnvW1Xo8fEwPmmV2+Tk6ygGCePi8TH5NPNcoDg46A2aBwTWzn4/f1mFmlrK6yWBW8sD1NF3FaCGfFXcNZ/Krrv4IN1DYmXfZXZc9Q7YPDyFM9/zqYt4SJFWIQRZH/MaJunuT7AkdZAkKsH/F1gLuL61JckfGwE+qDOsw==;
- In-reply-to: <CADjGqHuZpMyRCvEMivTZhW63Dk0wgSR8K+q0Whd_MhW57qB0Ag@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CADjGqHuZpMyRCvEMivTZhW63Dk0wgSR8K+q0Whd_MhW57qB0Ag@mail.gmail.com>
TJ Luoma wrote:
> function if they do the same thing?
>
> For example, these are (as far as I know) functionally identical:
>
> function timestamp_r { strftime "%Y/%m/%d at %-I:%M:%S %p"
> "$EPOCHSECONDS" }
>
> alias timestamp_r='strftime "%Y/%m/%d at %-I:%M:%S %p" "$EPOCHSECONDS"'
>
> Is there any reason to prefer one or the other?
If you find your function finishes by passing "$@" as the last argument
to whatever command it is, then there's a good chance that an alias will
suffice. Note that (unless you unsetopt completealiases), completion
after an alias will look at the alias definition so with, e.g:
alias ll='ls -lFb'
ll -<tab>
this will still complete options to ls. With the function equivalent that
won't work without an explicit compdef.
Functions can be more flexible with their arguments. For example, the
following slight modification to your function makes EPOCHSECONDS
merely a default if you don't specify a different time. This is not
possible with an alias:
function timestamp_r { strftime "%Y/%m/%d at %-I:%M:%S %p" "${1:-$EPOCHSECONDS}" }
Oliver
Messages sorted by:
Reverse Date,
Date,
Thread,
Author