Created
January 27, 2012 06:22
-
-
Save jaesharp/1687362 to your computer and use it in GitHub Desktop.
Bash snippet to display RVM gemset and ruby information, and git status
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
# Based on script at http://snipplr.com/view/36724/ , modified to be more like the default shell prompt | |
function detect_rvm_version { | |
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}') | |
[ "$gemset" != "" ] && gemset="@$gemset" | |
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}') | |
[ "$version" != "" ] && version="$version" | |
local full="$version$gemset" | |
[ "$full" != "" ] && echo "$full" | |
} | |
function detect_git_dirty { | |
local git_status=$(git status 2>&1 | tail -n1) | |
[[ $git_status != "fatal: Not a git repository (or any of the parent directories): .git" ]] && [[ $git_status != "nothing to commit (working directory clean)" ]] && echo "*" | |
} | |
function detect_git_branch { | |
local branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/") | |
if [[ $branch = "" ]] | |
then | |
echo $branch | |
else | |
echo " $branch" | |
fi | |
} | |
function dev_info { | |
info="$(detect_rvm_version)$(detect_git_branch)$(detect_git_dirty)" | |
if [[ $info = "" ]] | |
then | |
echo ""; | |
else | |
echo " [$info]" | |
fi | |
} | |
# Colors | |
txtred='\e[0;31m' # Red | |
txtwht='\e[0;37m' # White | |
txtrst='\e[0m' # Text Reset | |
export GIT_DISCOVERY_ACROSS_FILESYSTEM=true | |
# Custom command prompt | |
export PS1="\u@\h \[$txtwht\]\w\[$txtred\]\$(dev_info)\[$txtrst\]\$ " | |
# If you don't have colors, use something like this instead: | |
# export PS1="\w \$(dev_info) " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment