Created
March 20, 2012 16:18
-
-
Save mariusae/2137803 to your computer and use it in GitHub Desktop.
Format scala imports
This file contains hidden or 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
#!/bin/bash | |
norm(){ | |
awk ' | |
/^import/ { | |
if(current) print current | |
current = $0 | |
} | |
$0 !~ /^import/ { | |
current = current $0 | |
} | |
END{ | |
if(current) print current | |
}' | |
} | |
ifmt(){ | |
awk ' | |
length > 80 && /{/ { | |
i = index($0, "{") | |
pre = substr($0, 1, i) | |
post = substr($0, i+1, length($0)) | |
sub("}.*$", "", post) | |
gsub(" +", " ", post) | |
print pre | |
line = " " | |
n=split(post, fs, ", *") | |
for(i in fs){ | |
sub("^ +", "", fs[i]) | |
sub(" +$", "", fs[i]) | |
} | |
asort(fs) | |
for(i=1; i<=n; i++){ | |
# if empty, continue, and n--? | |
line = line fs[i] | |
if(i!=n) | |
line = line ", " | |
if(i==n) | |
print line "}" | |
else if(length(line) > 70){ | |
print line | |
line = " " | |
} | |
} | |
next; | |
} | |
{print} | |
' | |
} | |
norm|sort|ifmt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment