Skip to content

Commit 26d4cbe

Browse files
jaimergpkenodegard
andauthored
Fix hook in csh (#14)
Co-authored-by: Ken Odegard <[email protected]>
1 parent 0b6127d commit 26d4cbe

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

conda_spawn/activate.py

+24-23
Original file line numberDiff line numberDiff line change
@@ -895,13 +895,7 @@ class CshActivator(_Activator):
895895
set_var_tmpl = "set %s='%s'"
896896
run_script_tmpl = 'source "%s"'
897897

898-
hook_source_path = Path(
899-
CONDA_PACKAGE_ROOT,
900-
"shell",
901-
"etc",
902-
"profile.d",
903-
"conda.csh",
904-
)
898+
hook_source_path = None # see _hook_preamble
905899

906900
def _update_prompt(self, set_vars, conda_prompt_modifier):
907901
prompt = os.getenv("prompt", "")
@@ -915,24 +909,31 @@ def _update_prompt(self, set_vars, conda_prompt_modifier):
915909
)
916910

917911
def _hook_preamble(self) -> str:
912+
# TCSH/CSH removes newlines when doing command substitution (see `man tcsh`),
913+
# source conda.csh directly and use line terminators to separate commands
914+
hook_source_path = Path(
915+
CONDA_PACKAGE_ROOT,
916+
"shell",
917+
"etc",
918+
"profile.d",
919+
"conda.csh",
920+
)
918921
if on_win:
919-
return dedent(
920-
f"""
921-
setenv CONDA_EXE `cygpath {context.conda_exe}`
922-
setenv _CONDA_ROOT `cygpath {context.conda_prefix}`
923-
setenv _CONDA_EXE `cygpath {context.conda_exe}`
924-
setenv CONDA_PYTHON_EXE `cygpath {sys.executable}`
925-
"""
926-
).strip()
922+
return (
923+
f"setenv CONDA_EXE \"`cygpath '{context.conda_exe}'`\";\n"
924+
f"setenv _CONDA_ROOT \"`cygpath '{context.conda_prefix}'`\";\n"
925+
f"setenv _CONDA_EXE \"`cygpath '{context.conda_exe}'`\";\n"
926+
f"setenv CONDA_PYTHON_EXE \"`cygpath '{sys.executable}'`\";\n"
927+
f"source \"`cygpath '{hook_source_path}'`\";\n"
928+
)
927929
else:
928-
return dedent(
929-
f"""
930-
setenv CONDA_EXE "{context.conda_exe}"
931-
setenv _CONDA_ROOT "{context.conda_prefix}"
932-
setenv _CONDA_EXE "{context.conda_exe}"
933-
setenv CONDA_PYTHON_EXE "{sys.executable}"
934-
"""
935-
).strip()
930+
return (
931+
f'setenv CONDA_EXE "{context.conda_exe}";\n'
932+
f'setenv _CONDA_ROOT "{context.conda_prefix}";\n'
933+
f'setenv _CONDA_EXE "{context.conda_exe}";\n'
934+
f'setenv CONDA_PYTHON_EXE "{sys.executable}";\n'
935+
f'source "{hook_source_path}";\n'
936+
)
936937

937938

938939
class XonshActivator(_Activator):

0 commit comments

Comments
 (0)