Skip to content

Instantly share code, notes, and snippets.

@henrik242
Last active January 11, 2019 10:57
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 henrik242/dffbb1ed850610ce26d55c486ee25567 to your computer and use it in GitHub Desktop.
Save henrik242/dffbb1ed850610ce26d55c486ee25567 to your computer and use it in GitHub Desktop.
Preliminary work that commits renames of .java files to .kt, and renames them back to prepare for IntelliJ code conversion
#!/usr/bin/env bash
set -o errexit -o pipefail -o nounset
if [[ $# -eq 0 ]]; then
echo "Usage: $0 someclass.java [someotherclass.groovy ...]"
exit 1
fi
printf "\n\nMoving files with git\n\n"
function resolveFile {
EXT=${1##*.}
BASE=$(basename $1 .$EXT)
BASEFILE=$(dirname $1)/$BASE
}
for file in $@; do
if [[ ! -f $file ]]; then
echo Error: Does not exist: $file
exit 1
fi
resolveFile $file
git mv -v $file $BASEFILE.kt \
&& FILES+="-i $BASEFILE.kt -i $file " \
&& NAMES+="$BASE "
done
if [[ -n "$FILES" ]]; then
printf "\n\nCommitting\n\n"
git commit -m"$NAMES -> kt, part 1" $FILES
printf "\n\nMoving files back\n\n"
for file in $@; do
resolveFile $file
mv -v $BASEFILE.kt $BASEFILE.java
done
printf "\n\nOkay, if there are no errors above, run Code » Convert Java to Kotlin in IntelliJ\n\n"
else
printf "\n\nSomething failed\n\n"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment