Last active
May 10, 2020 17:30
-
-
Save mczuchnowski/e2c154f5be9e4dc1e95e to your computer and use it in GitHub Desktop.
Supercool bash prompt with rvm and git integration
This file contains hidden or 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
| # This allows us to use __git_ps1 | |
| # Get it from https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh | |
| source ~/git-prompt.sh | |
| # Reset | |
| Color_Off="\[\033[0m\]" # Text Reset | |
| Green="\[\033[0;32m\]" # Green | |
| IBlue="\[\033[0;94m\]" # Blue | |
| IRed="\[\033[0;91m\]" # Red | |
| Yellow="\[\033[0;33m\]" # Yellow | |
| BYellow="\[\033[1;33m\]" # Yellow | |
| # Various variables you might want for your PS1 prompt | |
| Time12h="\T" | |
| Time12a="\@" | |
| PathShort="\w" | |
| PathFull="\W" | |
| # Defining rvm display | |
| function __my_rvm_ruby_version { | |
| local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') | |
| [ "$gemset" != "" ] && gemset="@$gemset" | |
| local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') | |
| [ "$version" == "1.8.7" ] && version="" | |
| local full="$version$gemset" | |
| [ "$full" != "" ] && echo "$full" | |
| } | |
| # Defining the whole whole prompt with git branch/status | |
| export PS1=$IBlue'$(__my_rvm_ruby_version)'$Color_Off'$(git branch &>/dev/null;\ | |
| if [ $? -eq 0 ]; then \ | |
| echo "$(echo `git status` | grep "nothing to commit" > /dev/null 2>&1; \ | |
| if [ "$?" -eq "0" ]; then \ | |
| # @4 - Clean repository - nothing to commit | |
| echo "'$Green'"$(__git_ps1 " (%s)"); \ | |
| else \ | |
| # @5 - Changes to working tree | |
| echo "'$IRed'"$(__git_ps1 " {%s}"); \ | |
| fi) '$BYellow$PathShort$Color_Off'\$ "; \ | |
| else \ | |
| # @2 - Prompt when not in GIT repo | |
| echo " '$Yellow$PathShort$Color_Off'\$ "; \ | |
| fi)' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment