Created
July 23, 2020 18:48
-
-
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
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
# 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