Skip to content

Instantly share code, notes, and snippets.

@j33ty
Last active May 16, 2019 19:11
Show Gist options
  • Save j33ty/c7ddb74b1dc8ee07d7941ede42aef956 to your computer and use it in GitHub Desktop.
Save j33ty/c7ddb74b1dc8ee07d7941ede42aef956 to your computer and use it in GitHub Desktop.
Print Go package names in tree form
SEDMAGIC='s;/[^/]*;|____;g;s;____|; |;g'
for f in $(find . -name "*.go" -print); do
line=$(head -n 1 "$f");
[[ ! -z "$line" ]] && [[ "$line" =~ ^package[\ ][a-z_]+$ ]] && is_package=true
if [ "$is_package" = true ]; then
tree=$(echo "$f" | sed -e "$SEDMAGIC");
package_name=$(echo $line | cut -d' ' -f 2);
echo "$tree $package_name"
fi
done
@j33ty
Copy link
Author

j33ty commented May 16, 2019

TODO: Duplicate package names in tree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment