Created
July 29, 2021 22:44
-
-
Save andrewmeissner/639d00ee70d8985d2a1104522550ee18 to your computer and use it in GitHub Desktop.
remove all blank lines in go 'imports' statements, then sort with `goimports`
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 | |
# remove all blank lines in go 'imports' statements, | |
# then sort with goimports | |
if [ $# != 1 ] ; then | |
echo "usage: $0 <filename>" | |
exit 1 | |
fi | |
# gsed for osx | |
gsed -i ' | |
/^import/,/)/ { | |
/^$/ d | |
} | |
' $1 | |
goimports -w $1 | |
# usage for an entire directory: find . -type f -name "*.go" | xargs -I {} goimports2 {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment