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

Re: activate alias inside subshell




Some elegant solution?


    " As a consequence, aliases defined in a function are not
    available until after that function is executed. To be safe,
    always put alias definitions on a separate line, and do not use
    alias in compound commands.

And another quote, this time from |zsh| manual:

    There is a commonly encountered problem with aliases illustrated
    by the following code:

    |alias echobar='echo bar';echobar|

    This prints a message that the command echobar could not be found."

Ok, that is clear.  Too bad whence seems to report the thing as active, that had me beating my head against the wall.  Something like a runtime expansion would be a nice option to have but it seems that unheard of.   But another mystery:


   mag=$'\e[35;1m'
   cyn=$'\e[36;1m'
   nrm=$'\e[0m'

   yelline () { echo -e "$yel$@$nrm" }

   function msg () { echo -e "${grn}$@${nrm}" }
   alias msg='yelline ${(%):-%x %I}:'

   function test1 ()
   {
   (
   whence -va msg; declare -f msg
   msg one

   msg () { echo nulled }

   whence -va msg; declare -f msg
   msg where has the alias gone?
   echo "\n==========================\n"
   )
   }

Output:

    $ . test1; test1

   msg is an alias for yelline ${(%):-%x %I}: <<  fine
   msg is a shell function from test1                  << fine,
   function is right and alias is there
   msg () {
        echo -e "${grn}$@${nrm}"
   }
   test1 14: one <<  fine, the alias is  in effect.
   msg is an alias for yelline ${(%):-%x %I}:     << ok ..
   msg is a shell function from test1                 << ... but the
   function is not updated and ...
   msg () {
        echo -e "${grn}$@${nrm}"
   }
   nulled                                                  << ... the
   changed function now overrides the alias!

... in practice this is exactly what I need in the current situation -- to kill either function or alias, but it does seem strange that changing a function causes it to override an alias.  Is this documented somewhere?







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