zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: activate alias inside subshell
Date: Sat, 7 Apr 2018 12:57:50 -0700	[thread overview]
Message-ID: <637434d9-ff23-53d4-5d31-443942fc2ef9@eastlink.ca> (raw)
In-Reply-To: <604319cb-d86f-686b-ac9b-00d21650edff@eastlink.ca>


> 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?



>


  reply	other threads:[~2018-04-07 20:27 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-06 16:29 Ray Andrews
2018-04-07 19:57 ` Ray Andrews [this message]
2018-04-08  7:39   ` Bart Schaefer
2018-04-08 14:56     ` Ray Andrews
2018-04-08 20:18       ` Bart Schaefer
2018-04-08 20:54         ` Ray Andrews
2018-04-08 22:38       ` Ray Andrews
2018-04-09  4:11         ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=637434d9-ff23-53d4-5d31-443942fc2ef9@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).