Skip to content

Instantly share code, notes, and snippets.

@Gazer

Gazer/.zshrc

Created Jul 23, 2020
Embed
What would you like to do?
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
You can’t perform that action at this time.