Skip to content

Instantly share code, notes, and snippets.

@NicolasDurant
Last active December 9, 2021 22:39
Show Gist options
  • Save NicolasDurant/cee661faf5a582901449b17b93fabe02 to your computer and use it in GitHub Desktop.
Save NicolasDurant/cee661faf5a582901449b17b93fabe02 to your computer and use it in GitHub Desktop.
[Flutter / Script - Assets generator] Generates a text file of all the assets in your assets folder, in a format that you can just copy paste into the pubspec.yml assets definition. #Flutter #!/bin/sh #Shell #Assets #Generation
#!/bin/sh
# If you don't have the GNU commands (amazing stuff) on your mac, install with:
# $ brew install autoconf bash binutils coreutils diffutils ed findutils flex gawk \
# gnu-indent gnu-sed gnu-tar gnu-which gpatch grep gzip less m4 make nano \
# screen watch wdiff wget
# If you don't have the tree command on your mac, install with:
# $ brew install tree
#
# Just a quick shell script that outputs all asset files with their path and writes them into assets_list.txt.
# Prefixed with "- assets/${path}" so you can copy that into the pubspec.yml.
# VARIABLES
LIST=$(tree -ifF | grep -v /$)
# COMMANDS
rm assets_list.txt
echo "$LIST" > assets_list.txt
gsed -i 's|\./\b|- assets/|g' assets_list.txt
gsed -i '1d' assets_list.txt
ghead -n -3 assets_list.txt > temp.txt
mv temp.txt assets_list.txt
gsed -i '1d' assets_list.txt
gsed -i '1s/^/# THIS IS AN AUTOGENERATED FILE, YOU CAN DELETE IT WIHTOUT CAUTION\n\n/' assets_list.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment