-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
activate.fish: support activating conda in fish shells (#342)
Co-authored-by: Uwe L. Korn <xhochy@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
82 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
function _activate | ||
set -l full_path_script_dir (cd (dirname (status -f)); and pwd) | ||
set -l full_path_env (dirname "$full_path_script_dir") | ||
set env_name (basename "$full_path_env") | ||
|
||
# If there's already a source env | ||
if [ -n "$CONDA_PREFIX" ] | ||
# If the source env differs from this env | ||
if [ "$CONDA_PREFIX" != "$full_path_env" ] | ||
deactivate | ||
else | ||
return 0 # nothing to do | ||
end | ||
end | ||
|
||
export CONDA_PREFIX="$full_path_env" | ||
set _OLD_PATH "$PATH" | ||
set PATH "$full_path_env/bin:$PATH" | ||
|
||
functions -c fish_prompt _old_fish_prompt | ||
function fish_prompt | ||
# Run the user's prompt first; it might depend on (pipe)status. | ||
set -l prompt (_old_fish_prompt) | ||
|
||
printf "($env_name) " | ||
|
||
string join -- \n $prompt # handle multi-line prompts | ||
end | ||
|
||
# Run the activate scripts | ||
set -l _script_dir "$full_path_env/etc/conda/activate.d" | ||
if [ -d "$_script_dir" ] && [ -n "(ls -A "$_script_dir")" ] | ||
set -l _path | ||
for _path in "$_script_dir"/*.sh | ||
# Normally these are sourced but given they're not-fish scripts it will | ||
# error out. Run them anyways for any side effects. | ||
sh "$_path" | ||
end | ||
for _path in "$_script_dir"/*.fish | ||
. "$_path" | ||
end | ||
end | ||
end | ||
|
||
function deactivate -d 'Exit conda mode and return to the normal environment.' | ||
# reset old environment variables | ||
if test -n "$_OLD_PATH" | ||
set -gx PATH $_OLD_PATH | ||
set -e _OLD_PATH | ||
end | ||
|
||
if functions -q _old_fish_prompt | ||
# Erase virtualenv's `fish_prompt` and restore the original. | ||
functions -e fish_prompt | ||
functions -c _old_fish_prompt fish_prompt | ||
functions -e _old_fish_prompt | ||
end | ||
|
||
set -e CONDA_PREFIX | ||
end | ||
|
||
_activate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters