Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: re-source rc atomically



Second time in a row precmd is a big part of the solution to my
problem - maybe I'll remember this next time :)

Thanks

On Wed, Jul 23, 2014 at 8:56 AM, Peter Stephenson
<p.stephenson@xxxxxxxxxxx> wrote:
> On Wed, 23 Jul 2014 08:02:27 -0400
> shawn wilson <ag4ve.us@xxxxxxxxx> wrote:
>> Is there a way to source my zshrc somewhat atomically?
>>
>> I wouldn't want to do this to all of my sessions in case I mess
>> something up. But it would be nice if this were re-sourced in most as
>> automatic as possible so that when I change an alias or add a new
>> function I don't have to remember what was added when and manually
>> source my config when something doesn't work as expected.
>
> I guess you know about ". ~/.zshrc" and are asking if there's a way to
> do that without you having to type it.
>
> You can do stuff like this.  Use the array precmd_functions if you
> have other things in precmd.
>
> precmd() {
>    local -a stat
>    integer last_change
>    zmodload -F zsh/stat b:zstat
>    zstat -A stat +mtime ~/.zshrc
>    last_change=$stat[1]
>    if [[ -n $ZSHRC_LAST_CHANGE && last_change -gt ZSHRC_LAST_CHANGE ]]; then
>      # We don't want this to occur in function scope.
>      trap '. ~/.zshrc' EXIT
>    fi
>    typeset -ig ZSHRC_LAST_CHANGE
>    ZSHRC_LAST_CHANGE=last_change
> }
>
>
> You'd better make sure .zshrc doesn't define a conflicting precmd(), of
> course (as mine just did...)
>
> You could loop over other functions if you wanted.
>
> pws



Messages sorted by: Reverse Date, Date, Thread, Author