Repository: conda/conda

Issue:
Conda init zsh ignores $ZDOTDIR variable
<!--
Hi!  Read this; it's important.

This is an issue tracker for conda -- the package manager.  File feature requests
for conda here, as well as bug reports about something conda has messed up.

If your issue is a bug report for:
  * a specific conda package from Anaconda ('defaults' channel):
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * a specific conda package from conda-forge:
      ==> file at the corresponding feedstock under https://github.com/conda-forge
  * repo.anaconda.com access and service:
      ==> file at https://github.com/ContinuumIO/anaconda-issues
  * anaconda.org access and service:
      ==> file at https://anaconda.org/contact/report
  * commands under 'conda build':
      ==> file at https://github.com/conda/conda-build
  * commands under 'conda env':
      ==> please file it here!
  * all other conda commands that start with 'conda':
      ==> please file it here!

If you continue on,

   **please include all requested information below.**

If a maintainer determines the information is required to understand 
your issue, and if it is not provided, your issue may be
closed automatically.

-->

## Current Behavior
<!-- What actually happens?
     If you want to include console output, please use "Steps to Reproduce" below. -->

When using `conda init zsh`, conda will create a .zshrc file in my `$HOME` directory instead of looking for one in my `$ZDOTDIR` directory.

I have set `$ZDOTDIR` in a .zshenv file (in `$HOME`), all my other zsh files, in particular .zshrc, are in `$ZDOTDIR`. Since this duplicate file created by conda won't be read by the shell, conda packages can't be called.


### Steps to Reproduce
<!-- If the current behavior is a bug, please provide specific, minimal steps to independently reproduce.
     Include the exact conda commands that reproduce the issue and their output between the ticks below. -->

On zsh:
Set `$ZDOTDIR` to a directory different from `$HOME`.
Move or create a .zshrc file in `$ZDOTDIR`.
run `conda init zsh`.

## Expected Behavior
<!-- What do you think should happen? -->

`Conda init zsh` should look for .zshrc in `$ZDOTDIR` ([as zsh does](http://zsh.sourceforge.net/Intro/intro_3.html)).

I understand the problem can easily be fixed by copy-pasting the text from one file to another,
but it would be better if the default behavior was to look for the .zshrc file in `$ZDOTDIR`.


## Environment Information
<details open><summary><code>`conda info`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda info' -->

```

     active environment : None
       user config file : /Users/sergioalejandro/.condarc
 populated config files :
          conda version : 4.7.12
    conda-build version : not installed
         python version : 3.7.3.final.0
       virtual packages :
       base environment : /usr/local/Caskroom/miniconda/base  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /usr/local/Caskroom/miniconda/base/pkgs
                          /Users/sergioalejandro/.conda/pkgs
       envs directories : /usr/local/Caskroom/miniconda/base/envs
                          /Users/sergioalejandro/.conda/envs
               platform : osx-64
             user-agent : conda/4.7.12 requests/2.22.0 CPython/3.7.3 Darwin/19.0.0 OSX/10.15
                UID:GID : 501:20
             netrc file : None
           offline mode : False

```
</p></details>


<details open><summary><code>`conda config --show-sources`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda config --show-sources' -->

```

```
</p></details>


<details><summary><code>`conda list --show-channel-urls`</code></summary><p>
<!-- between the ticks below, paste the output of 'conda list --show-channel-urls' -->

```
# packages in environment at /usr/local/Caskroom/miniconda/base:
#
# Name                    Version                   Build  Channel
appnope                   0.1.0                    py37_0    defaults
asn1crypto                1.2.0                    py37_0    defaults
attrs                     19.3.0                     py_0    defaults
backcall                  0.1.0                    py37_0    defaults
bleach                    3.1.0                    py37_0    defaults
ca-certificates           2019.10.16                    0    defaults
certifi                   2019.9.11                py37_0    defaults
cffi                      1.13.0           py37hb5b8e2f_0    defaults
chardet                   3.0.4                 py37_1003    defaults
conda                     4.7.12                   py37_0    defaults
conda-package-handling    1.6.0            py37h1de35cc_0    defaults
cryptography              2.8              py37ha12b0ac_0    defaults
dbus                      1.13.6               h90a0687_0    defaults
decorator                 4.4.0                    py37_1    defaults
defusedxml                0.6.0                      py_0    defaults
entrypoints               0.3                      py37_0    defaults
expat                     2.2.6                h0a44026_0    defaults
gettext                   0.19.8.1             h15daf44_3    defaults
glib                      2.56.2               hd9629dc_0    defaults
icu                       58.2                 h4b95b61_1    defaults
idna                      2.8                      py37_0    defaults
importlib_metadata        0.23                     py37_0    defaults
ipykernel                 5.1.2            py37h39e3cac_0    defaults
ipython                   7.8.0            py37h39e3cac_0    defaults
ipython_genutils          0.2.0                    py37_0    defaults
ipywidgets                7.5.1                      py_0    defaults
jedi                      0.15.1                   py37_0    defaults
jinja2                    2.10.3                     py_0    defaults
jpeg                      9b                   he5867d9_2    defaults
jsonschema                3.1.1                    py37_0    defaults
jupyter                   1.0.0                    py37_7    defaults
jupyter_client            5.3.4                    py37_0    defaults
jupyter_console           6.0.0                    py37_0    defaults
jupyter_core              4.6.0                    py37_0    defaults
libcxx                    4.0.1                hcfea43d_1    defaults
libcxxabi                 4.0.1                hcfea43d_1    defaults
libedit                   3.1.20181209         hb402a30_0    defaults
libffi                    3.2.1                h475c297_4    defaults
libiconv                  1.15                 hdd342a3_7    defaults
libpng                    1.6.37               ha441bb4_0    defaults
libsodium                 1.0.16               h3efe00b_0    defaults
markupsafe                1.1.1            py37h1de35cc_0    defaults
mistune                   0.8.4            py37h1de35cc_0    defaults
more-itertools            7.2.0                    py37_0    defaults
nbconvert                 5.6.0                    py37_1    defaults
nbformat                  4.4.0                    py37_0    defaults
ncurses                   6.1                  h0a44026_1    defaults
notebook                  6.0.1                    py37_0    defaults
openssl                   1.1.1d               h1de35cc_3    defaults
pandoc                    2.2.3.2                       0    defaults
pandocfilters             1.4.2                    py37_1    defaults
parso                     0.5.1                      py_0    defaults
pcre                      8.43                 h0a44026_0    defaults
pexpect                   4.7.0                    py37_0    defaults
pickleshare               0.7.5                    py37_0    defaults
prometheus_client         0.7.1                      py_0    defaults
prompt_toolkit            2.0.10                     py_0    defaults
ptyprocess                0.6.0                    py37_0    defaults
pycosat                   0.6.3            py37h1de35cc_0    defaults
pycparser                 2.19                     py37_0    defaults
pygments                  2.4.2                      py_0    defaults
pyopenssl                 19.0.0                   py37_0    defaults
pyqt                      5.9.2            py37h655552a_2    defaults
pyrsistent                0.15.4           py37h1de35cc_0    defaults
pysocks                   1.7.1                    py37_0    defaults
python                    3.7.3                h359304d_0    defaults
python-dateutil           2.8.0                    py37_0    defaults
python.app                2                        py37_9    defaults
pyzmq                     18.1.0           py37h0a44026_0    defaults
qt                        5.9.7                h468cd18_1    defaults
qtconsole                 4.5.5                      py_0    defaults
readline                  7.0                  h1de35cc_5    defaults
requests                  2.22.0                   py37_0    defaults
ruamel_yaml               0.15.46          py37h1de35cc_0    defaults
send2trash                1.5.0                    py37_0    defaults
setuptools                41.4.0                   py37_0    defaults
sip                       4.19.8           py37h0a44026_0    defaults
six                       1.12.0                   py37_0    defaults
sqlite                    3.30.0               ha441bb4_0    defaults
terminado                 0.8.2                    py37_0    defaults
testpath                  0.4.2                    py37_0    defaults
tk                        8.6.8                ha441bb4_0    defaults
tornado                   6.0.3            py37h1de35cc_0    defaults
tqdm                      4.36.1                     py_0    defaults
traitlets                 4.3.3                    py37_0    defaults
urllib3                   1.24.2                   py37_0    defaults
wcwidth                   0.1.7                    py37_0    defaults
webencodings              0.5.1                    py37_1    defaults
widgetsnbextension        3.5.1                    py37_0    defaults
xz                        5.2.4                h1de35cc_4    defaults
yaml                      0.1.7                hc338f04_2    defaults
zeromq                    4.3.1                h0a44026_3    defaults
zipp                      0.6.0                      py_0    defaults
zlib                      1.2.11               h1de35cc_3    defaults
```
</p></details>



Discussion:

Resolving patch:
diff --git a/conda/core/initialize.py b/conda/core/initialize.py
--- a/conda/core/initialize.py
+++ b/conda/core/initialize.py
@@ -450,7 +450,10 @@ def make_initialize_plan(conda_prefix, shells, for_user, for_system, anaconda_pr
             })
 
         if 'zsh' in shells and for_user:
-            zshrc_path = expand(join('~', '.zshrc'))
+            if 'ZDOTDIR' in os.environ:
+                zshrc_path = expand(join("$ZDOTDIR", ".zshrc"))
+            else:
+                zshrc_path = expand(join('~', '.zshrc'))
             plan.append({
                 'function': init_sh_user.__name__,
                 'kwargs': {


Test patch: