最近在用fish shell,但是无法使用conda的activate命令来激活环境.官方给的有解决方案
https://github.com/conda/conda/blob/5b97a96d78e65d8178eb60d36e0fc99cd5b3ab21/bin/conda.fish
将这个里面的内容复制到自己的config.fish在source一下就可以了
#
# Conda environment activate / deactivate functions for fish shell v2.2.0+.
#
# Ivan Smirnov (C)
# #
# INSTALL
#
# Source this file from the fish shell to enable activate / deactivate functions.
# In order to automatically load these functions on fish startup, append
#
# source (conda info --root)/bin/conda.fish
#
# to the end of your ~/.config/config.fish file.
#
# USAGE
#
# To activate an environment (via name or path), you can use one of the following:
#
# activate ENV
# conda activate ENV
#
# To deactivate an environment, use one of:
#
# deactivate
# conda deactivate
#
# To make the env name appear on the left side, set an environment variable:
#
# set -gx CONDA_LEFT_PROMPT
#
# To go back to making the env name appear on the right, erase that variable:
#
# set -e CONDA_LEFT_PROMPT # Require version fish v2.+ to be able to use array slices, `else if`
# and $status for command substitutions
if [ (echo (fish -v ^&) | sed 's/^.*version \([0-9]\)\..*$/\1/') -lt ]
echo 'Incompatible fish shell version; please upgrade to v2.0 or higher.'
exit
end function __conda_delete_function
functions -e $argv
if functions -q $argv
functions -e $argv
end
end function __conda_restore_prompt
if functions -q __fish_prompt_orig
__conda_delete_function fish_prompt
functions -c __fish_prompt_orig fish_prompt
functions -e __fish_prompt_orig
end if functions -q __fish_right_prompt_orig
__conda_delete_function fish_right_prompt
functions -c __fish_right_prompt_orig fish_right_prompt
functions -e __fish_right_prompt_orig
end
end function __conda_backup_prompt
functions -e __fish_prompt_orig
if functions -q fish_prompt
functions -c fish_prompt __fish_prompt_orig
functions -e fish_prompt
else
function __fish_prompt_orig
end
end functions -e __fish_right_prompt_orig
if functions -q fish_right_prompt
functions -c fish_right_prompt __fish_right_prompt_orig
functions -e fish_right_prompt
else
function __fish_right_prompt_orig
end
end
end function __conda_echo_env
set_color normal
echo -n '('
set_color -o green
echo -n $CONDA_DEFAULT_ENV
set_color normal
echo -n ') '
end # Inject environment name into fish_right_prompt / fish_prompt
function __conda_update_prompt
if [ (conda '..changeps1') -eq ]
switch $argv[]
case activate
__conda_restore_prompt
__conda_backup_prompt
function fish_prompt
if set -q CONDA_LEFT_PROMPT
__conda_echo_env
end
__fish_prompt_orig
end
function fish_right_prompt
if not set -q CONDA_LEFT_PROMPT
__conda_echo_env
end
__fish_right_prompt_orig
end
case deactivate
__conda_restore_prompt
end
end
end # Convert colon-separated path to a legit fish list
function __conda_set_path
set -gx PATH (echo $argv[] | tr : \n)
end # Calls activate / deactivate functions if the first argument is activate or
# deactivate; otherwise, calls conda-<cmd> and passes the arguments through
function conda
if [ (count $argv) -lt ]
command conda
else
if [ (count $argv) -gt ]
set ARGS $argv[..-]
else
set -e ARGS
end
switch $argv[]
case activate deactivate
eval $argv
case '*'
command conda $argv
end
end
end # Equivalent to bash version of conda activate script
function activate --description 'Activate a conda environment.'
if [ (count $argv) -lt ]
echo 'You need to specify a conda environment.'
return
end # deactivate an environment first if it's set
if set -q CONDA_DEFAULT_ENV
conda '..checkenv' $argv[]
if [ $status = ]
__conda_set_path (conda '..deactivate')
set -e CONDA_DEFAULT_ENV
__conda_update_prompt deactivate
else
return
end
end # try to activate the environment
set -l NEW_PATH (conda '..activate' $argv[])
if [ $status = ]
__conda_set_path $NEW_PATH
if [ (echo $argv[] | grep '/') ]
pushd (dirname $argv[])
set -gx CONDA_DEFAULT_ENV (pwd)/(basename $argv[])
popd
else
set -gx CONDA_DEFAULT_ENV $argv[]
end
__conda_update_prompt activate
else
return $status
end
end # Equivalent to bash version of conda deactivate script
function deactivate --description 'Deactivate the current conda environment.'
if set -q CONDA_DEFAULT_ENV # don't deactivate the root environment
set -l NEW_PATH (conda '..deactivate' $argv[])
if [ $status = ]
__conda_set_path $NEW_PATH
set -e CONDA_DEFAULT_ENV
__conda_update_prompt deactivate
else
return $status
end
end
# return
end