Skip to content

Instantly share code, notes, and snippets.

@realyze
Created December 8, 2017 02:49
Show Gist options
  • Save realyze/5c118df24ee418eae9523fd4b7009792 to your computer and use it in GitHub Desktop.
Save realyze/5c118df24ee418eae9523fd4b7009792 to your computer and use it in GitHub Desktop.
FILES=$(git diff --name-only `git merge-base HEAD green`)
FORMAT_BIN=${HOME}/.ideaformatter/Contents/bin/format.sh
if [[ ! -f ${FORMAT_BIN} ]]; then
echo 'Please symlink idea into $HOME/.ideaformatter';
exit 1;
fi
FILES_ARR=($FILES)
ABS_FILES=( "${FILES_ARR[@]/#/`cd .. && pwd`/}" )
echo "Formatting ${ABS_FILES[@]}"
SETTINGS_FILE=`pwd`/.idea/codeStyleSettings.xml
cd ~/.ideaformatter/Contents/bin && ./format.sh -s ${SETTINGS_FILE} ${ABS_FILES[@]}
@alextreppass
Copy link

alextreppass commented Dec 8, 2017

The following works better for me -- it only formats changed files (checked out + staged). I was finding the branch-based approach touch to use.

I have IJ installed standalone and not as part of the toolbox.

Assumes $CANVA points to your canva dir (which can be set up in your ~/.bashrc, sourced from ~/.bash_profile):

SETTINGS_FILE=$CANVA/.idea/codeStyleSettings.xml
FILES=$(git diff --name-only HEAD')
FILES_ARR=($FILES)
ABS_FILES=( "${FILES_ARR[@]/#/`cd .. && pwd`/}" )
(cd /Applications/IntelliJ\ IDEA.app/Contents/bin && ./format.sh -s $SETTINGS_FILE ${ABS_FILES[@]})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment