Skip to content

Instantly share code, notes, and snippets.

@dumazy
Created October 31, 2020 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dumazy/b5f64d4c544489569b65be7a30990983 to your computer and use it in GitHub Desktop.
Save dumazy/b5f64d4c544489569b65be7a30990983 to your computer and use it in GitHub Desktop.
Flutter sandbox script
#!/bin/bash
# Absolute path of the Flutter sandbox project
sandbox_path="/Users/fre.dumazy/Developer/Playground/flutter_sandbox"
# Name of Android emulator to open.
# Check with `emulator -list-avds`
avd_name="Pixel_4_API_30"
main() {
processOptions "$@"
resetSandbox
openVsCode
}
openVsCode () {
# Open the project in VS Code at the main.dart file
code "$sandbox_path" "$sandbox_path/lib/main.dart"
}
usage () {
echo "Usage: $0 [-i] [-a]"
}
processOptions () {
while getopts ":ia" flag; do
case "${flag}" in
i)
startSimulator
;;
a)
startEmulator
;;
*)
usage
;;
esac
done
}
startSimulator () {
open -a Simulator
}
startEmulator () {
# Start emulator in a background process and ignore logs in terminal
emulator -avd "$avd_name" > /dev/null 2>&1 &
}
resetSandbox () {
(cd "$sandbox_path" && git reset --hard > /dev/null 2>&1)
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment