Created
June 9, 2023 10:14
-
-
Save wilsonsilva/9399e55d89bd37f926e376d09eeb0311 to your computer and use it in GitHub Desktop.
Renames MyApp and MainApp to App in the Flutter app templates
This file contains 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 | |
# Get the location of the Flutter SDK | |
flutter_path=$(which flutter) | |
# Check if Flutter SDK is found | |
if [[ -z "$flutter_path" ]]; then | |
echo "Flutter SDK not found. Please install Flutter and add it to your PATH." | |
exit 1 | |
fi | |
flutter_path=${flutter_path%/*/*} | |
# Get the path to the file to be patched | |
file_to_patch="$flutter_path/packages/flutter_tools/templates/app/lib/main.dart.tmpl" | |
# Check if the file exists | |
if [[ ! -f "$file_to_patch" ]]; then | |
echo "File not found!" | |
exit 1 | |
fi | |
# Use awk to replace all instances of MyApp and MainApp to App | |
echo "Creating patch for ${file_to_patch}" | |
awk ' | |
{ gsub("MyApp","App"); gsub("MainApp","App"); print } | |
' "$file_to_patch" > temp | |
# Show a diff before patching | |
echo "Here is the proposed change:" | |
diff --color -u "$file_to_patch" temp | |
# Ask the user if they want to proceed | |
read -p "Do you want to apply these changes? (y/n) " answer | |
case ${answer:0:1} in | |
y|Y ) | |
echo "Applying changes..." | |
mv temp "$file_to_patch" | |
;; | |
* ) | |
echo "Aborting..." | |
rm temp | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run this every time you update the SDK. Use it with
flutter create -e myapp
to generate a minimallib/main.dart
.Before:
After: