Skip to content

Instantly share code, notes, and snippets.

@obscurerichard
Last active December 14, 2024 01:43
Show Gist options
  • Save obscurerichard/4d4c803b64872e5bcd4a28d02e2ed289 to your computer and use it in GitHub Desktop.
Save obscurerichard/4d4c803b64872e5bcd4a28d02e2ed289 to your computer and use it in GitHub Desktop.

Revisions

  1. obscurerichard revised this gist Dec 14, 2024. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions protect-conda-base.sh
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,18 @@
    # protect-conda-base.sh
    #
    # If you use Anaconda, it is really easy to accidentally install packages
    # into the base environment. Head that off at the pass.
    # However, allow installs in a pip virtual environment.
    #
    # Allow for an override if you run these commands with a CONDA_PROMPT_OVERRIDE variable set,
    # as in:
    #
    # CONDA_PROMPT_OVERRIDE pip install powerline-shell
    #
    # Include this in your .bashrc or .zshrc
    #
    # Thanks https://stackoverflow.com/a/69617319/424301

    function pip(){
    if [ -z "${CONDA_PROMPT_OVERRIDE}" ] && [ -z "${VIRTUAL_ENV}" ] && [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then
    echo "Not allowed in base"
  2. obscurerichard revised this gist Dec 14, 2024. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions protect-conda-base.sh
    Original file line number Diff line number Diff line change
    @@ -7,18 +7,18 @@
    #
    # Thanks https://stackoverflow.com/a/69617319/424301
    function pip(){
    if [ -z "${VIRTUAL_ENV}" ] && [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then
    if [ -z "${CONDA_PROMPT_OVERRIDE}" ] && [ -z "${VIRTUAL_ENV}" ] && [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then
    echo "Not allowed in base"
    else
    command pip "$@"
    fi
    }

    function extended_conda(){
    if [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then
    if [ -z "${CONDA_PROMPT_OVERRIDE}" ] && [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then
    echo "Not allowed in base"
    else
    conda "$@"
    fi
    }
    alias conda=extended_conda
    alias conda=extended_conda
  3. obscurerichard created this gist Dec 14, 2024.
    24 changes: 24 additions & 0 deletions protect-conda-base.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    # protect-conda-base.sh
    # If you use Anaconda, it is really easy to accidentally install packages
    # into the base environment. Head that off at the pass.
    # However, allow installs in a pip virtual environment.
    #
    # Include this in your .bashrc or .zshrc
    #
    # Thanks https://stackoverflow.com/a/69617319/424301
    function pip(){
    if [ -z "${VIRTUAL_ENV}" ] && [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then
    echo "Not allowed in base"
    else
    command pip "$@"
    fi
    }

    function extended_conda(){
    if [ "${CONDA_PROMPT_MODIFIER-}" = "(base) " ] && [ "$1" = "install" ]; then
    echo "Not allowed in base"
    else
    conda "$@"
    fi
    }
    alias conda=extended_conda