Skip to content

Instantly share code, notes, and snippets.

@jaredyam
Last active January 22, 2021 12:42
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 jaredyam/601f3ae66d9994766c8f2ba4741e4769 to your computer and use it in GitHub Desktop.
Save jaredyam/601f3ae66d9994766c8f2ba4741e4769 to your computer and use it in GitHub Desktop.
# Rename conda env and redirect bash shebang to new env.
#
# Reference
# ---------
# https://stackoverflow.com/a/62853056/11533669
# rename
# The two variables below should be something like path str or filename if the file presents in current directory
mv $OLD_ENV_NAME $NEW_ENV_NAME
# modify bash shebang
## GNU/Linux
sed -i "s:$(head -1 $NEW_ENV_NAME/bin/pip):#\!$PWD/$NEW_ENV_NAME/bin/python:" $NEW_ENV_NAME/bin/*
## FreeBSD/MacOS
gsed -i "s:$(head -1 $NEW_ENV_NAME/bin/pip):#\!$PWD/$NEW_ENV_NAME/bin/python:" $NEW_ENV_NAME/bin/*
# or wrap up to a function (MacOS case)
# $1: old env name; $2: new env name
function rename-env() {
mv $1 $2
gsed -i "s:$(head -1 $2/bin/pip):#\!$PWD/$2/bin/python:" $2/bin/*
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment