Skip to content

Instantly share code, notes, and snippets.

@mczuchnowski
Last active May 10, 2020 17:30
Show Gist options
  • Select an option

  • Save mczuchnowski/e2c154f5be9e4dc1e95e to your computer and use it in GitHub Desktop.

Select an option

Save mczuchnowski/e2c154f5be9e4dc1e95e to your computer and use it in GitHub Desktop.
Supercool bash prompt with rvm and git integration
# 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