Skip to content

Instantly share code, notes, and snippets.

@Gazer
Created July 23, 2020 18:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Gazer/cc9ac339d9c53fc86fd928cce4133a22 to your computer and use it in GitHub Desktop.
Save Gazer/cc9ac339d9c53fc86fd928cce4133a22 to your computer and use it in GitHub Desktop.
Some zsh magic to detect and change the current Flutter version needed by an app in the current directory
# Add this to your ~/.zshrc AFTER the last export PATH="" that is currenttly defined
# Change these to reflect where do you have Flutter installed
export FLUTTER_STABLE_PATH="$HOME/dev/flutter/bin"
export FLUTTER_BETA_PATH="$HOME/dev/flutter-beta/bin"
export FLUTTER_MASTER_PATH="$HOME/dev/flutter-master/bin"
export BASE_PATH=$PATH
# Using 💙 until we can get a Flutter emoji :)
function useFlutterStable() {
export RPROMPT=""
export PATH="$BASE_PATH:$FLUTTER_STABLE_PATH"
}
function useFlutterBeta() {
export RPROMPT="💙 %{$fg[yellow]%}Beta%{$reset_color%}"
export PATH="$BASE_PATH:$FLUTTER_BETA_PATH"
}
function useFlutterMaster() {
export RPROMPT="💙 %{$fg_bold[red]%}Master%{$reset_color%}"
export PATH="$BASE_PATH:$FLUTTER_MASTER_PATH"
}
_check_needed_flutter_version() {
# TODO : We need to look on the root of the flutter app, but for now this
# will work
VERSION=`cat $PWD/.flutter_version 2>/dev/null || echo 'stable'`
if [ "master" = "$VERSION" ] ; then
useFlutterMaster
fi
if [ "stable" = "$VERSION" ] ; then
useFlutterStable
fi
if [ "beta" = "$VERSION" ] ; then
useFlutterBeta
fi
}
useFlutterStable
precmd_functions+=(_check_needed_flutter_version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment