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

activate alias inside subshell

Sourcing this:


   alias msg='echo $cyn alias outside $nrm'
   whence -v msg
   msg "called outside"

   function test1 ()
   msg "called inside"
   unalias msg
   alias msg='echo $mag alias inside $nrm'
   whence -v msg
   msg "called inside function"
   echo "\nnow test:\n"

   whence -v msg
   msg "called outside function"

   echo "\n==================================\n"

I get:

   15 /aWorking/Zsh/Source/Wk 7 $ . test1
   msg is an alias for echo $cyn alias outside $nrm << fine
     alias outside  called outside << fine

   now test:

     alias outside  called inside << fine
   msg is an alias for echo $mag alias inside $nrm << whence is correct
     alias outside  called inside function << but the old alias is used
   msg is an alias for echo $cyn alias outside $nrm << original alias
   undisturbed, good.
     alias outside  called outside function   << fine


... so I have an apparent localization of the alias as far as whence is concerned but it is not acted upon.  Can that be rectified?  I tried a few variations, one succeeds in having it exactly backwards, the external alias is used inside and the redefined alias is used externally, but a second run fixes that, it seems the alias must always be defined before the function is sourced.  Can we have instant gratification with an alias change inside a function?  I'd have thought that the subshell would make it easy.  In any case one would think that the alias that whence reports would be the alias in effect.

What I'm actually trying to do is reduce verbosity of a function by redefining various message printer functions as null.  It works fine with functions, but if the message printers are aliases (which seem to be the only way to get:  ${(%):-%x %I} ... line information printed, it seems that can't be done in a function) ... then it goes sour.  For example:

    [[ "$vverbose" < 3 ]] &&
        warningmsg () { ; }

... I kill the message by nullifying the function that prints it (it's nothing but a colorized line).  In the subshell it's all local, no damage outside the function.  But when debugging I like the line numbers, so 'warningmsg' becomes an alias:

    alias warningmsg=' echo -en "${(%):-%x %I}: " && magline ' # Just colorizes.  I wish we could do that in a function.

... but now, when I want to kill messages, as above, efforts to neuter the alias fail.  The whole thing is very suspect.  I had thought to redefine the alias like this:

        local alias warningmsg='#'

... which is probably outrageous, but the idea is that it would turn the text of the message into a comment.  I'm probably best to forget the whole thing, but I do love the line numbers and killing messages by nullifying message functions works like a charm ... but not with aliases.  Can I have my cake and eat it too?  Some elegant solution?

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