Skip to content

Instantly share code, notes, and snippets.

@jklukas
Last active August 29, 2015 14:20
Show Gist options
  • Save jklukas/0222a2da435a12823055 to your computer and use it in GitHub Desktop.
Save jklukas/0222a2da435a12823055 to your computer and use it in GitHub Desktop.
Break long compound imports to multiple lines (Scala)
for x in $(gsed -n -E -e 's/.*(class|object|trait) ([[:alnum:]]*).*/\2/p' nacho-wire/src/main/scala/com/simple/nacho/wire/Json.scala); do
find nacho-service -name "*.scala" | \
xargs sed -i '' '/^import/! s/\([^.[:alnum:]]\)\('$x'[[:punct:][:space:]]\)/\1wire.\2/g';
done
# Invoke as:
# sed -f break-up-imports.sed file.scala
# Only act on import statements with at least 5 items
/import .*,.*,.*,.*,.*/ {
# Add a newline after the opening brace
s/{/{\
/
# Add a newline before closing brace
s/}/\
}/
# Add newlines between commas
s/, /,\
/g
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment