zsh-users
 help / color / mirror / code / Atom feed
From: "Dupéron Georges" <jahvascriptmaniac@gmail.com>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: some color fails in command.
Date: Tue, 8 Aug 2017 22:51:40 +0200	[thread overview]
Message-ID: <CAKQnwqZCLEWtWgENwJMbZC+Fz3AKfhTV3QCF3XtPPYQ0dPoPmg@mail.gmail.com> (raw)
In-Reply-To: <3d606eba-4475-8676-0fe5-f189062d5b65@eastlink.ca>

[-- Attachment #1: Type: text/plain, Size: 2579 bytes --]

Sorry I went off-list by accident there. I'm putting back the list in CC.

2017-08-08 22:37 GMT+02:00 Ray Andrews <rayandrews@eastlink.ca>:
>
> Right, the 'fg' stuff isn't native to echo.  I've asked this before, but
> how do I get a command to pick up any and all settings?   Is it simply a
> case of sourcing .zshrc?  That sounds simplest and best.  Mind, I find that
> when I create a command file it is usually because I want a clean slate, so
> .... Or I want it on the path and sourced scripts aren't searched for the
> same way, or are they?  Can it be done?
>

Sourcing ~/.zshrc seems like a big hammer for a small issue, a lot of
people have huge ~/.zshrc configurations.

If you want to simply add a small utility command to your own shell, write
it as a function in a separate file, and source that small file from your
~/.zshrc.

If you want to write a standalone command (e.g. that can be used by other
people which may have a different config) then as you say, it's better to
start with a blank slate, and load what you need. I bet most of the
contents of ~/.zshrc will be related to the prompt, auto-completion and
other interactive behaviour, so the amount of things that you have to load
manually will likely be small.

fg is simply an array containing the escape sequences for the various
colours, and is indeed not specific to echo. Since it is a variable (well,
an array) changing the PATH won't affect the presence or absence of fg.
When you write autoload colors && colors, it has a similar effect to
sourcing (not just running) a script which would populate the fg array and
a few others.

This probably doesn't matter, but is there some intuitive reason why $PATH
> would be imported but $fg not?
>

PATH is normally explicitly exported with:

export PATH

or

export PATH="/home/me/bin:$PATH"

which explicitly tells the shell to make that variable available to child
processes.

I don't know a way to export an array (hopefully someone more knowledgeable
here will chime in about that), only simple scalar variables. But relying
on too much things being present in the environment is usually a bad thing,
as it makes your script more fragile and less likely to work on different
configurations. relying on PATH, HOME and similar universal env vars is
okay, and so is the use of env vars as switches which alter the behaviour
of your script (they effectively become part of the "normal" way of calling
your script, if you document them properly), but relying on the environment
to contain utilities does not seem like a good idea to me.

Cheers,
Georges

  parent reply	other threads:[~2017-08-08 20:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-08 19:39 Ray Andrews
2017-08-08 20:16 ` Peter Stephenson
2017-08-08 20:51 ` Dupéron Georges [this message]
2017-08-09  3:09   ` Ray Andrews
2017-08-09  3:58     ` Bart Schaefer
2017-08-09 14:09       ` 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=CAKQnwqZCLEWtWgENwJMbZC+Fz3AKfhTV3QCF3XtPPYQ0dPoPmg@mail.gmail.com \
    --to=jahvascriptmaniac@gmail.com \
    --cc=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).