shell script to clone Idea Project into another directory

I could not find a formal way of making a copy of a project on a different directory so I've made this shell script to accomplish this.
I wanted to save project states across some online trainning sessions.

Here it is:

#!/bin/sh
# Author: Reginaldo Costa
# usage: cloneIdea.sh <directory of project to be cloned>  <new directory>

if [ ! -d "$1" ] ; then
    echo "No directory $1 found"
    exit 8
fi
if [ -d "$2" ] ; then
    echo "Directory $2 found. Delete the directoty 1st if you want to override it"
    exit 12
fi

echo "..... Copying project files into new project directory $NEWPROJ"
cp -vr $1 $2

echo "..... Going to new project directory"
cd $2

echo ".... Changing references"
OLDPROJ=${1##/*/}
NEWPROJ=${PWD##/*/}
set -x
find . -type f -name '*' | xargs grep -H "$OLDPROJ"   | awk -F: '{print $1}' | sort | uniq | xargs -n 1 sed -i '.bak' \
        "s/$OLDPROJ/$NEWPROJ/g"
set -

echo ".... renaming project descriptor file"
mv -v $OLDPROJ.iml $NEWPROJ.iml

#Comment the following lines if you want to keep the .bak files.
echo ".... Deleting the old files"
find . -type f -name *.bak -exec rm -v {} \;

Message was edited by: Reginaldo Costa The find / arg statement needs to be  on one line only or  two lines separated by "|" as a last character of a preceding line



Attachment(s):
cloneIdea.sh

Please sign in to leave a comment.