Skip to content

Instantly share code, notes, and snippets.

@kidpixo
Last active November 28, 2022 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kidpixo/19e5961a7522f0d57529b00f3e866633 to your computer and use it in GitHub Desktop.
Save kidpixo/19e5961a7522f0d57529b00f3e866633 to your computer and use it in GitHub Desktop.
Update all conda enviroment, optionally using another executable like mamba and dry run option setting from cli.
# define CONDACOMMAND externally to overwrite this, I use conda or mamba
# default is to use mamba, a looooot faster
CONDACOMMAND=${1:-'mamba'}
# DRYRUNCONDACOMMAND : is set to anything, just print the commands
if [ -z $DRYRUNCONDACOMMAND ]
then
echo "DRYRUNCONDACOMMAND is unset, this is the real stuff"
DRYRUNCONDACOMMAND=''
else
echo "DRYRUNCONDACOMMAND is set, this is a dry run"
DRYRUNCONDACOMMAND='echo'
printf "use :\n unset DRYRUNCONDACOMMAND\nto clean the variable for a real run\n"
fi
# # Debug
# echo "CONDACOMMAND=$CONDACOMMAND"
# echo "DRYRUNCONDACOMMAND=$DRYRUNCONDACOMMAND"
# # print all envs
# echo $(eval $($CONDACOMMAND env list) | sed '/^#/d;/^$/d' | awk '{print $1}')
# # set env to base
# local env=base
# # run one loop cycle
# $DRYRUNCONDACOMMAND $CONDACOMMAND update -n $env --all -y
# list all envs
for env in $($CONDACOMMAND env list | sed '/^#/d;/^$/d' | awk '{print $1}')
do
printf '=%.0s' {1..100} # envs separator
echo
echo "updating enviroment: $env"
echo "--------------------------" # print current env name
echo
$DRYRUNCONDACOMMAND $CONDACOMMAND update -n $env --all -y # update everything
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment