Skip to content

Instantly share code, notes, and snippets.

@devraj
Last active June 6, 2020 01:45
Show Gist options
  • Save devraj/d7c639a5a4e08117a2bfc10253a52818 to your computer and use it in GitHub Desktop.
Save devraj/d7c639a5a4e08117a2bfc10253a52818 to your computer and use it in GitHub Desktop.
Changes directory names and package reference of a Docker + Python project
# Created for internal project automation, might not be releveant for others
# except as a learning exercise for bash tricks
# Portions require revision to make it more efficient - produciton like :)
# Please use a template for your own work.
# Change names of directories
FROM="proj1"; TO="proj2"; for FROM_DIR in `find . -name $FROM`; do if [ -d $FROM_DIR ]; then TARGET_DIR=`echo $FROM_DIR | sed "s/$FROM/$TO/g"`; echo $FROM_DIR ">" $TARGET_DIR; mv $FROM_DIR $TARGET_DIR; fi ; done
# Replace references to package names
FROM="proj1"; TO="proj2"; for SRC_FILE in `ls **/*.py **/Makefile **/*.yml **/Dockerfile **/*.dockerfile **/alembic.ini **/.env* **/README.md `; do sed -i '' "s/$FROM/$TO/g" $SRC_FILE; done
# Do the above in one step
FROM="proj1"; TO="proj2"; for FROM_DIR in `find . -name $FROM`; do if [ -d $FROM_DIR ]; then TARGET_DIR=`echo $FROM_DIR | sed "s/$FROM/$TO/g"`; echo $FROM_DIR ">" $TARGET_DIR; mv $FROM_DIR $TARGET_DIR; fi ; done; for SRC_FILE in `ls **/*.py **/Makefile **/*.yml **/Dockerfile **/*.dockerfile **/alembic.ini **/.env* **/README.md `; do sed -i '' "s/$FROM/$TO/g" $SRC_FILE; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment