Last active
May 16, 2019 19:11
-
-
Save rdyv/c7ddb74b1dc8ee07d7941ede42aef956 to your computer and use it in GitHub Desktop.
Print Go package names in tree form
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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: Duplicate package names in tree.