* Can an alias ever have a dynamic element?
@ 2013-12-17 15:20 zzapper
2013-12-17 16:04 ` Phil Pennock
2013-12-17 17:15 ` Bart Schaefer
0 siblings, 2 replies; 4+ messages in thread
From: zzapper @ 2013-12-17 15:20 UTC (permalink / raw)
To: zsh-users
Hi
I have an alias which creates a tar with a date component in its name that
date is however evaluated when the shell is created which could have been a
few days ago. The easy solution is to create a script but is they any
alternative?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can an alias ever have a dynamic element?
2013-12-17 15:20 Can an alias ever have a dynamic element? zzapper
@ 2013-12-17 16:04 ` Phil Pennock
2013-12-17 17:15 ` Bart Schaefer
1 sibling, 0 replies; 4+ messages in thread
From: Phil Pennock @ 2013-12-17 16:04 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
On 2013-12-17 at 15:20 +0000, zzapper wrote:
> I have an alias which creates a tar with a date component in its name that
> date is however evaluated when the shell is created which could have been a
> few days ago. The easy solution is to create a script but is they any
> alternative?
Use a function.
There are a very few use-cases for aliases, which mostly boil down to
"need to mess with how zsh parses the command-line"; otherwise, you
should use functions. Use functions unless and until you know you need
an alias.
"alias -g" for in-place mutations, or plain aliases which tinker with
state in some other way, but otherwise, use functions.
function tar_with_initial_timestamp {
zmodload -i zsh/datetime || return 1
local invoked_s invoked_rendered
invoked_s=$(( EPOCHSECONDS - SECONDS ))
TZ="" strftime -s invoked_rendered "%Y%m%d_%H%M%SZ" $invoked_s
tar cvf "capture_$invoked_rendered.tar" "$@"
}
tar_with_initial_timestamp dir1 dir2 metadata.json
-Phil
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can an alias ever have a dynamic element?
2013-12-17 15:20 Can an alias ever have a dynamic element? zzapper
2013-12-17 16:04 ` Phil Pennock
@ 2013-12-17 17:15 ` Bart Schaefer
2013-12-17 18:41 ` zzapper
1 sibling, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2013-12-17 17:15 UTC (permalink / raw)
To: zsh-users
On Dec 17, 3:20pm, zzapper wrote:
}
} I have an alias which creates a tar with a date component in its name
} that date is however evaluated when the shell is created which could
} have been a few days ago. The easy solution is to create a script but
} is they any alternative?
This usually means you've created the alias with something like:
alias thingy="foo $(date)"
when what you need are single rather than double quotes:
alias thingy='foo $(date)'
Always best if you actually show us an example rather than attempt to
describe it in prose.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Can an alias ever have a dynamic element?
2013-12-17 17:15 ` Bart Schaefer
@ 2013-12-17 18:41 ` zzapper
0 siblings, 0 replies; 4+ messages in thread
From: zzapper @ 2013-12-17 18:41 UTC (permalink / raw)
To: zsh-users
Bart Schaefer > }
> } I have an alias which creates a tar with a date component in its name
> } that date is however evaluated when the shell is created which could
> } have been a few days ago. The easy solution is to create a script but
> } is they any alternative?
>
> This usually means you've created the alias with something like:
>
> alias thingy="foo $(date)"
>
> when what you need are single rather than double quotes:
>
> alias thingy='foo $(date)'
>
>
LOL I foolishly never realised that single and double quotes behaved
differently for aliases!!
alias maketar='dw && zargs ./**/*.{php,inc,js} -- tar rvf /tmp/serviceplan
$(date "+%d-%m-%Y").tar
Thanks Bart
https://twitter.com/dailyzshtip
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-12-17 18:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-17 15:20 Can an alias ever have a dynamic element? zzapper
2013-12-17 16:04 ` Phil Pennock
2013-12-17 17:15 ` Bart Schaefer
2013-12-17 18:41 ` zzapper
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).