Skip to content

Commit

Permalink
Merge pull request conda#7041 from njalerikson/fix-csh-prompt
Browse files Browse the repository at this point in the history
Fix csh prompt
  • Loading branch information
kalefranz authored Mar 21, 2018
2 parents 3b86094 + 7906ee0 commit 546cd78
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ record.txt
Vagrantfile
docs/_build
env/
.pytest_cache/
11 changes: 6 additions & 5 deletions conda/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, shell, arguments=None):
self.shift_args = 0
self.command_join = ';\n'

self.unset_var_tmpl = 'unset %s'
self.unset_var_tmpl = 'unsetenv %s'
self.export_var_tmpl = 'setenv %s "%s"'
self.set_var_tmpl = "set %s='%s'"
self.run_script_tmpl = 'source "%s"'
Expand Down Expand Up @@ -227,7 +227,7 @@ def build_activate(self, env_name_or_prefix):
old_conda_prefix = self.environ.get('CONDA_PREFIX')
max_shlvl = context.max_shlvl

if old_conda_prefix == prefix:
if old_conda_prefix == prefix and old_conda_shlvl > 0:
return self.build_reactivate()
if self.environ.get('CONDA_PREFIX_%s' % (old_conda_shlvl-1)) == prefix:
# in this case, user is attempting to activate the previous environment,
Expand Down Expand Up @@ -291,9 +291,10 @@ def build_activate(self, env_name_or_prefix):

def build_deactivate(self):
# query environment
old_conda_prefix = self.environ.get('CONDA_PREFIX')
old_conda_shlvl = int(self.environ.get('CONDA_SHLVL', 0))
old_conda_prefix = self.environ.get('CONDA_PREFIX', None)
if old_conda_shlvl <= 0 or old_conda_prefix is None:
if not old_conda_prefix or old_conda_shlvl < 1:
# no active environment, so cannot deactivate; do nothing
return {
'unset_vars': (),
'set_vars': {},
Expand Down Expand Up @@ -351,7 +352,7 @@ def build_deactivate(self):

def build_reactivate(self):
conda_prefix = self.environ.get('CONDA_PREFIX')
conda_shlvl = int(self.environ.get('CONDA_SHLVL', -1))
conda_shlvl = int(self.environ.get('CONDA_SHLVL', 0))
if not conda_prefix or conda_shlvl < 1:
# no active environment, so cannot reactivate; do nothing
return {
Expand Down
14 changes: 7 additions & 7 deletions conda/shell/etc/profile.d/conda.csh
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ else
endif
endif

if (`alias conda` == "") then
if ("`alias conda`" == "") then
if ($?_CONDA_ROOT) then
alias conda source $_CONDA_ROOT/etc/profile.d/conda.csh
alias conda source "${_CONDA_ROOT}/etc/profile.d/conda.csh"
else
alias conda source $PWD/conda/shell/etc/profile.d/conda.csh
alias conda source "${PWD}/conda/shell/etc/profile.d/conda.csh"
endif
setenv CONDA_SHLVL 0
if (! $?prompt) then
set prompt=""
endif
else
switch ( $1 )
switch ( "${1}" )
case "activate":
eval `$_CONDA_EXE shell.csh activate "$2" $argv[3-]`
eval "`(setenv prompt '${prompt}' ; '${_CONDA_EXE}' shell.csh activate '${2}' ${argv[3-]})`"
rehash
breaksw
case "deactivate":
eval `$_CONDA_EXE shell.csh deactivate "$2" $argv[3-]`
eval "`(setenv prompt '${prompt}' ; '${_CONDA_EXE}' shell.csh deactivate '${2}' ${argv[3-]})`"
rehash
breaksw
case "install" | "update" | "uninstall" | "remove":
$_CONDA_EXE $argv[1-]
eval `$_CONDA_EXE shell.csh reactivate`
eval "`(setenv prompt '${prompt}' ; '${_CONDA_EXE}' shell.csh reactivate)`"
rehash
breaksw
default:
Expand Down
12 changes: 6 additions & 6 deletions tests/test_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,11 +687,11 @@ def test_csh_basic(self):
new_path = activator.pathsep_join(activator._remove_prefix_from_path(self.prefix))
assert deactivate_data == dals("""
source "%(deactivate1)s";
unset CONDA_DEFAULT_ENV;
unset CONDA_EXE;
unset CONDA_PREFIX;
unset CONDA_PROMPT_MODIFIER;
unset CONDA_PYTHON_EXE;
unsetenv CONDA_DEFAULT_ENV;
unsetenv CONDA_EXE;
unsetenv CONDA_PREFIX;
unsetenv CONDA_PROMPT_MODIFIER;
unsetenv CONDA_PYTHON_EXE;
set prompt='%(prompt)s';
setenv CONDA_SHLVL "0";
setenv PATH "%(new_path)s";
Expand Down Expand Up @@ -1146,7 +1146,7 @@ def basic_csh(self, shell):
shell.assert_env_var('CONDA_SHLVL', '0')

@pytest.mark.skipif(not which('csh'), reason='csh not installed')
@pytest.mark.xfail(reason="csh needs work apparently; but at least tcsh works")
@pytest.mark.xfail(reason="pure csh doesn't support argument passing to sourced scripts")
def test_csh_basic_integration(self):
with InteractiveShell('csh') as shell:
self.basic_csh(shell)
Expand Down

0 comments on commit 546cd78

Please sign in to comment.