-
-
Save an2nb2/94138d7b029f108f3894 to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# Add this to the end of .bashrc | |
# prompt with ruby version | |
# rbenv version | sed -e 's/ .*//' | |
__rbenv_ps1 () | |
{ | |
rbenv_ruby_version=`rbenv version | sed -e 's/ .*//'` | |
printf $rbenv_ruby_version | |
} | |
color_txt_blue='\e[0;34m' | |
color_txt_green='\e[0;32m' | |
color_txt_yellow='\e[0;33m' | |
color_txt_red='\e[0;31m' | |
color_txt_white='\e[0;37m' | |
color_txt_dark_grey='\e[90m' | |
color_txt_default='\e[39m' | |
rbenv_installed () { | |
[[ -f `which rbenv` ]] | |
} | |
ruby_selected () { | |
[[ `rbenv version` != "system "* ]] | |
} | |
git_ps1_available () { | |
[[ `type __git_ps1 | head -n 1` = "__git_ps1 is a function" ]] | |
} | |
git_repo_detected () { | |
git status &> /dev/null | |
} | |
git_branch_color () { | |
case `git symbolic-ref --short HEAD` in | |
'master') | |
echo $color_txt_red | |
;; | |
'dev') | |
echo $color_txt_yellow | |
;; | |
*) | |
echo $color_txt_green | |
;; | |
esac | |
} | |
ruby_version_name () { | |
if rbenv_installed && ruby_selected; then | |
echo "\[$color_txt_dark_grey\]ruby-$(__rbenv_ps1)" | |
fi | |
} | |
git_branch_name () { | |
if git_ps1_available && git_repo_detected; then | |
echo "\[$(git_branch_color)\]$(__git_ps1)" | |
fi | |
} | |
current_working_dir () { | |
echo " \[$color_txt_white\]\w" | |
} | |
bash_prompt_sign () { | |
echo "\[$color_txt_default\]\$" | |
} | |
current_user_with_host () { | |
if rbenv_installed && ruby_selected; then | |
echo "" | |
else | |
echo " \[$color_txt_dark_grey\]\u@\h" | |
fi | |
} | |
set_bash_prompt () { | |
PS1="$(current_user_with_host)$(current_working_dir) $(ruby_version_name)$(git_branch_name)$(bash_prompt_sign) " | |
} | |
export PROMPT_COMMAND=set_bash_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment