Repository: conda/conda

Issue:
Updated to conda 4.4.4, can't activate any environment
I just updated to 4.4.4, and now activation fails on a bash syntax error at the PS1 configuration, even for a freshly created env:
```bash
conda create -n foo -y -q  python
````

then:

```bash
alpamayo[junk]> conda activate foo
bash: syntax error near unexpected token `('
alpamayo[junk]> source activate foo
bash: eval: line 58: syntax error near unexpected token `('
bash: eval: line 58: `PS1='(foo) \[\033[0;32m\]$(__git_ps1 '(%s)')\[\033[1;31m\]\[\033[1;34m\]\h[\[\033[1;36m\]\W\[\033[1;34m\]]\[\033[1;32m\]> \[\033[0m\]''
````

Some conda info:

```bash
alpamayo[junk]> conda --version
conda 4.4.4
alpamayo[junk]> conda info -a

     active environment : None
            shell level : 0
       user config file : /Users/fperez/.condarc
 populated config files : /Users/fperez/.condarc
          conda version : 4.4.4
    conda-build version : not installed
         python version : 3.6.4.final.0
       base environment : /Users/fperez/usr/conda  (writable)
           channel URLs : https://repo.continuum.io/pkgs/main/osx-64
                          https://repo.continuum.io/pkgs/main/noarch
                          https://repo.continuum.io/pkgs/free/osx-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/osx-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/osx-64
                          https://repo.continuum.io/pkgs/pro/noarch
          package cache : /Users/fperez/usr/conda/pkgs
                          /Users/fperez/.conda/pkgs
       envs directories : /Users/fperez/usr/conda/envs
                          /Users/fperez/.conda/envs
               platform : osx-64
             user-agent : conda/4.4.4 requests/2.18.4 CPython/3.6.4 Darwin/16.7.0 OSX/10.12.6
                UID:GID : 33212:20665
             netrc file : None
           offline mode : False
```

Any tips? thanks!


Discussion:
Can you give me the output of 

    echo "$PS1"

in a new terminal window?
```
alpamayo[~]> echo "$PS1"
\[\033[0;32m\]$(__git_ps1 '(%s)')\[\033[1;31m\]\[\033[1;34m\]\h[\[\033[1;36m\]\W\[\033[1;34m\]]\[\033[1;32m\]> \[\033[0m\]
```
ps - for now I'm back to being able to work by reverting to 4.3.31, so no biggie (I tried all in the 4.4.x series with similar problems). Thanks for the quick response!
Ok I’ll work with your ps1 in a little while to see if I can come up with a solution. Thanks for the report. 
No worries, thanks much!

I wasn't expecting a reply on xmas, btw. Please take a break :)


Resolving patch:
diff --git a/conda/activate.py b/conda/activate.py
--- a/conda/activate.py
+++ b/conda/activate.py
@@ -426,6 +426,10 @@ def _update_prompt(self, set_vars, conda_prompt_modifier):
             current_prompt_modifier = os.environ.get('CONDA_PROMPT_MODIFIER')
             if current_prompt_modifier:
                 ps1 = re.sub(re.escape(current_prompt_modifier), r'', ps1)
+            # Because we're using single-quotes to set shell variables, we need to handle the
+            # proper escaping of single quotes that are already part of the string.
+            # Best solution appears to be https://stackoverflow.com/a/1250279
+            ps1 = ps1.replace("'", "'\"'\"'")
             set_vars.update({
                 'PS1': conda_prompt_modifier + ps1,
             })


Test patch: