Skip to content

Instantly share code, notes, and snippets.

@andrewmeissner
Created July 29, 2021 22:44
Show Gist options
  • Save andrewmeissner/639d00ee70d8985d2a1104522550ee18 to your computer and use it in GitHub Desktop.
Save andrewmeissner/639d00ee70d8985d2a1104522550ee18 to your computer and use it in GitHub Desktop.
remove all blank lines in go 'imports' statements, then sort with `goimports`
#!/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