Skip to content

Instantly share code, notes, and snippets.

@chbrandt
Created May 19, 2021 16:28
Show Gist options
  • Save chbrandt/a3cad4ef448e4220567cfd3665b2214c to your computer and use it in GitHub Desktop.
Save chbrandt/a3cad4ef448e4220567cfd3665b2214c to your computer and use it in GitHub Desktop.
Clean Conda init from bashrc
#!/bin/bash
awk '/>>> conda initialize >>>/ {p=1}; /<<< conda initialize <<</ {p=0; next}; {if (p==0) print $0}' .bashrc
@chbrandt
Copy link
Author

chbrandt commented May 19, 2021

Filter block of text/lines between >>> conda initialize >>> and <<< conda initialize <<< (inclusive):
print everything else BUT the block.

For example, part of my .bashrc:

# (. . .)

# Alias definitions.
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/opt/conda/bin/conda' 'shell.bash' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/opt/conda/etc/profile.d/conda.sh" ]; then
        . "/opt/conda/etc/profile.d/conda.sh"
    else
        export PATH="/opt/conda/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

# (. . .)

Would print:

# (. . .)

# Alias definitions.
if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# (. . .)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment