Snippets

Richard Plevin deactivate.cygwin: Anaconda "deactivate" script modified to work under cygwin

Created by Richard Plevin

File deactivate.cygwin Added

  • Ignore whitespace
  • Hide word diff
+#!/bin/bash
+
+#
+# Add this to your Anaconda2/Scripts directory alongside the standard "deactivate" script.
+# The only change is at line 91. The problem is that conda can't handle "/cygdrive/..."
+# style pathnames. The added call to "cygpath" corrects the pathname.
+#
+
+# Determine the directory containing this script
+if [[ -n $BASH_VERSION ]]; then
+    _SCRIPT_LOCATION=${BASH_SOURCE[0]}
+    _SHELL="bash"
+elif [[ -n $ZSH_VERSION ]]; then
+    _SCRIPT_LOCATION=${funcstack[1]}
+    _SHELL="zsh"
+else
+    echo "Only bash and zsh are supported"
+    return 1
+fi
+_CONDA_DIR=$(dirname "$_SCRIPT_LOCATION")
+
+case "$(uname -s)" in
+    CYGWIN*|MINGW*|MSYS*)
+        EXT=".exe"
+        export MSYS2_ENV_CONV_EXCL=CONDA_PATH
+        ;;
+    *)
+        EXT=""
+        ;;
+esac
+
+# shift over all args.  We don't accept any, so it's OK that we ignore them all here.
+while [[ $# > 0 ]]
+do
+    key="$1"
+    case $key in
+        -h|--help)
+            "$_CONDA_DIR/conda" ..deactivate $_SHELL$EXT -h
+            if [[ -n $BASH_VERSION ]] && [[ "$(basename "$0" 2> /dev/null)" == "deactivate" ]]; then
+                exit 0
+            else
+                return 0
+            fi
+            ;;
+    esac
+    shift # past argument or value
+done
+
+# Ensure that this script is sourced, not executed
+# Note that if the script was executed, we're running inside bash!
+# Also note that errors are ignored as `activate foo` doesn't generate a bad
+# value for $0 which would cause errors.
+if [[ -n $BASH_VERSION ]] && [[ "$(basename "$0" 2> /dev/null)" == "deactivate" ]]; then
+    (>&2 echo "Error: deactivate must be sourced. Run 'source deactivate'
+instead of 'deactivate'.
+")
+    "$_CONDA_DIR/conda" ..deactivate $_SHELL$EXT -h
+    exit 1
+fi
+
+if [[ -z "$CONDA_PATH_BACKUP" ]]; then
+    if [[ -n $BASH_VERSION ]] && [[ "$(basename "$0" 2> /dev/null)" == "deactivate" ]]; then
+        exit 0
+    else
+        return 0
+    fi
+fi
+
+if (( $? == 0 )); then
+    # Inverse of activation: run deactivate scripts prior to deactivating env
+    _CONDA_D="${CONDA_PREFIX}/etc/conda/deactivate.d"
+    if [[ -d $_CONDA_D ]]; then
+        eval $(find "$_CONDA_D" -iname "*.sh" -exec echo source \'{}\'';' \;)
+    fi
+
+#    # get the activation path that would have been provided for this prefix
+#    _LAST_ACTIVATE_PATH=$("$_CONDA_DIR/conda" ..activate $_SHELL$EXT "$CONDA_PREFIX")
+#
+#    # in activate, we replace a placeholder so that conda keeps its place in the PATH order
+#    # The activate script sets _CONDA_HOLD here to activate that behavior.
+#    #   Otherwise, PATH is simply removed.
+#    if [ -n "$_CONDA_HOLD" ]; then
+#        export PATH="$($_CONDA_PYTHON2 -c "import re; print(re.sub(r'$_LAST_ACTIVATE_PATH(:?)', r'CONDA_PATH_PLACEHOLDER\1', '$PATH', 1))")"
+#    else
+#        export PATH="$($_CONDA_PYTHON2 -c "import re; print(re.sub(r'$_LAST_ACTIVATE_PATH(:?)', r'', '$PATH', 1))")"
+#    fi
+#
+#    unset _LAST_ACTIVATE_PATH
+
+    # Added by rjp to convert cydrive path back to Windows drive letter
+    CONDA_PREFIX=$(cygpath -w $CONDA_PREFIX)
+    export PATH=$("$_CONDA_DIR/conda" ..deactivate.path $_SHELL$EXT "$CONDA_PREFIX")
+
+    unset CONDA_DEFAULT_ENV
+    unset CONDA_PREFIX
+    unset CONDA_PATH_BACKUP
+    export PS1="$CONDA_PS1_BACKUP"
+    unset CONDA_PS1_BACKUP
+    unset _CONDA_PYTHON2
+else
+    unset _CONDA_PYTHON2
+    return $?
+fi
+
+if [[ -n $BASH_VERSION ]]; then
+    hash -r
+elif [[ -n $ZSH_VERSION ]]; then
+    rehash
+fi
HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.