Created
June 10, 2015 22:09
-
-
Save mariusae/5859e177580ae84ac4f6 to your computer and use it in GitHub Desktop.
ifmt
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
#!/bin/bash | |
norm(){ | |
gawk ' | |
/^import/ { | |
if(current) print current | |
current = $0 | |
} | |
$0 !~ /^import/ { | |
current = current $0 | |
} | |
END{ | |
if(current) print current | |
}' | |
} | |
ifmt(){ | |
gawk ' | |
length > 100 && /{/ { | |
i = index($0, "{") | |
pre = substr($0, 1, i) | |
post = substr($0, i+1, length($0)) | |
sub("}.*$", "", post) | |
gsub(" +", " ", post) | |
line = pre | |
n=split(post, fs, ", *") | |
for(i in fs){ | |
sub("^ +", "", fs[i]) | |
sub(" +$", "", fs[i]) | |
} | |
asort(fs) | |
print line | |
line = " " | |
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 "}" | |
# print "}" | |
} 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