codekingpro/portable-devtools
114k
1# This file must be used using `source bin/activate.fish` *within a running fish ( http://fishshell.com ) session*.2# Do not run it directly.3 4function _bashify_path -d "Converts a fish path to something bash can recognize"5 set fishy_path $argv6 set bashy_path $fishy_path[1]7 for path_part in $fishy_path[2..-1]8 set bashy_path "$bashy_path:$path_part"9 end10 echo $bashy_path11end12 13function _fishify_path -d "Converts a bash path to something fish can recognize"14 echo $argv | tr ':' '\n'15end16 17function deactivate -d 'Exit virtualenv mode and return to the normal environment.'18 # reset old environment variables19 if test -n "$_OLD_VIRTUAL_PATH"20 # https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling21 if test (echo $FISH_VERSION | head -c 1) -lt 322 set -gx PATH (_fishify_path "$_OLD_VIRTUAL_PATH")23 else24 set -gx PATH $_OLD_VIRTUAL_PATH25 end26 set -e _OLD_VIRTUAL_PATH27 end28 29 if test -n "$_OLD_VIRTUAL_PYTHONHOME"30 set -gx PYTHONHOME "$_OLD_VIRTUAL_PYTHONHOME"31 set -e _OLD_VIRTUAL_PYTHONHOME32 end33 34 if test -n "$_OLD_FISH_PROMPT_OVERRIDE"35 and functions -q _old_fish_prompt36 # Set an empty local `$fish_function_path` to allow the removal of `fish_prompt` using `functions -e`.37 set -l fish_function_path38 39 # Erase virtualenv's `fish_prompt` and restore the original.40 functions -e fish_prompt41 functions -c _old_fish_prompt fish_prompt42 functions -e _old_fish_prompt43 set -e _OLD_FISH_PROMPT_OVERRIDE44 end45 46 set -e VIRTUAL_ENV47 set -e VIRTUAL_ENV_PROMPT48 49 if test "$argv[1]" != 'nondestructive'50 # Self-destruct!51 functions -e pydoc52 functions -e deactivate53 functions -e _bashify_path54 functions -e _fishify_path55 end56end57 58# Unset irrelevant variables.59deactivate nondestructive60 61set -gx VIRTUAL_ENV '__VIRTUAL_ENV__'62 63# https://github.com/fish-shell/fish-shell/issues/436 altered PATH handling64if test (echo $FISH_VERSION | head -c 1) -lt 365 set -gx _OLD_VIRTUAL_PATH (_bashify_path $PATH)66else67 set -gx _OLD_VIRTUAL_PATH $PATH68end69set -gx PATH "$VIRTUAL_ENV"'/__BIN_NAME__' $PATH70 71# Prompt override provided?72# If not, just use the environment name.73if test -n '__VIRTUAL_PROMPT__'74 set -gx VIRTUAL_ENV_PROMPT '__VIRTUAL_PROMPT__'75else76 set -gx VIRTUAL_ENV_PROMPT (basename "$VIRTUAL_ENV")77end78 79# Unset `$PYTHONHOME` if set.80if set -q PYTHONHOME81 set -gx _OLD_VIRTUAL_PYTHONHOME $PYTHONHOME82 set -e PYTHONHOME83end84 85function pydoc86 python -m pydoc $argv87end88 89if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"90 # Copy the current `fish_prompt` function as `_old_fish_prompt`.91 functions -c fish_prompt _old_fish_prompt92 93 function fish_prompt94 # Run the user's prompt first; it might depend on (pipe)status.95 set -l prompt (_old_fish_prompt)96 97 printf '(%s) ' $VIRTUAL_ENV_PROMPT98 99 string join -- \n $prompt # handle multi-line prompts100 end101 102 set -gx _OLD_FISH_PROMPT_OVERRIDE "$VIRTUAL_ENV"103end104 