Last active
January 11, 2019 10:57
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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