Skip to content

Instantly share code, notes, and snippets.

@dsager
Last active April 25, 2017 13:30
Show Gist options
  • Save dsager/00cd8b16819b347999e4 to your computer and use it in GitHub Desktop.
Save dsager/00cd8b16819b347999e4 to your computer and use it in GitHub Desktop.
Shell Script to backup IntelliJ IDEA project settings
#! /bin/bash
BAKDIR="${HOME}/Dropbox/config-backup/intellij/project-settings"
BAKFILE="${BAKDIR}/idea-folders.txt"
#create backup folder
mkdir -p "${BAKDIR}"
# find all `.idea` folders in home
if [ ! -e "${BAKFILE}" ]; then
echo "creating backup file: ${BAKFILE}"
cd ~ && find . -type d -iname '.idea' | cut -sd / -f 2- > "${BAKFILE}"
else
echo "backup file already exists: ${BAKFILE}"
fi
# move settings and create symlink
while read FOLDER; do
if [ -d "${FOLDER}" ]; then
echo "backing up ${FOLDER}"
BAKFOLDER="${BAKDIR}/${FOLDER}"
if [ -e "${BAKFOLDER}/" ]; then
echo " - already present, skipping: ${BAKFOLDER}"
else
BAKFOLDERPARENT=`echo "${BAKDIR}/${FOLDER}" | sed 's/\/\.idea$//'`
mkdir -p ${BAKFOLDERPARENT}
echo " - moving folder: ${FOLDER}"
mv "${HOME}/${FOLDER}" "${BAKFOLDER}"
echo " - symlinking folder: ${BAKFOLDER}"
ln -s "${BAKFOLDER}" "${HOME}/${FOLDER}"
fi
else
echo " - not a folder, skipping: ${FOLDER}"
fi
echo ""
done <${BAKFILE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment