Created
October 10, 2012 18:24
-
-
Save mjgiarlo/3867480 to your computer and use it in GitHub Desktop.
handy bash modifications for Hydra hackers
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
# Makes your prompt look like: http://i.imgur.com/Q647p.png | |
# I put this stuff in .bashrc, but you may prefer .bash_profile or .profile | |
# ... | |
RED="\[\033[0;31m\]" | |
GREEN="\[\033[0;32m\]" | |
ORANGE="\[\033[0;33m\]" | |
BLUE="\[\033[0;34m\]" | |
PURPLE="\[\033[0;35m\]" | |
CYAN="\[\033[0;36m\]" | |
WHITE="\[\033[0;37m\]" | |
BOLD_RED="\[\033[1;31m\]" | |
BOLD_GREEN="\[\033[1;32m\]" | |
BOLD_ORANGE="\[\033[1;33m\]" | |
BOLD_BLUE="\[\033[1;34m\]" | |
BOLD_PURPLE="\[\033[1;35m\]" | |
BOLD_CYAN="\[\033[1;36m\]" | |
BOLD_GREY="\[\033[1;37m\]" | |
DARK_GREY="\[\033[0;90m\]" | |
LIGHT_RED="\[\033[0;91m\]" | |
LIGHT_GREEN="\[\033[0;92m\]" | |
YELLOW="\[\033[0;93m\]" | |
LIGHT_BLUE="\[\033[0;94m\]" | |
LIGHT_PURPLE="\[\033[0;95m\]" | |
TURQUOISE="\[\033[0;96m\]" | |
BOLD_WHITE="\[\033[0;97m\]" | |
COLOR_NONE="\[\e[0m\]" | |
function __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}') | |
local full="$version$gemset" | |
[ "$full" != "" ] && echo "${COLOR_NONE}[${WHITE}$full${COLOR_NONE}]" | |
} | |
function parse_git_branch { | |
git rev-parse --git-dir &> /dev/null | |
git_status="$(git status 2> /dev/null)" | |
branch_pattern="^# On branch ([^${IFS}]*)" | |
remote_pattern="# Your branch is (.*) of" | |
diverge_pattern="# Your branch and (.*) have diverged" | |
if [[ ! ${git_status} =~ "working directory clean" ]]; then | |
state="${BOLD_RED}⚡" | |
fi | |
# add an else if or two here if you want to get more specific | |
if [[ ${git_status} =~ ${remote_pattern} ]]; then | |
if [[ ${BASH_REMATCH[1]} == "ahead" ]]; then | |
remote="${YELLOW}↑" | |
else | |
remote="${YELLOW}↓" | |
fi | |
fi | |
if [[ ${git_status} =~ ${diverge_pattern} ]]; then | |
remote="${YELLOW}↕" | |
fi | |
if [[ ${git_status} =~ ${branch_pattern} ]]; then | |
branch=${BASH_REMATCH[1]} | |
echo " ${BOLD_WHITE}(${branch}$(__rvm_ruby_version)${remote}${state}${BOLD_WHITE})${COLOR_NONE}" | |
fi | |
} | |
function prompt_func() { | |
previous_return_value=$?; | |
prompt="${LIGHT_GREEN}\u@\h:${BLUE}\w${COLOR_NONE}$(parse_git_branch)${COLOR_NONE}" | |
if test $previous_return_value -eq 0 | |
then | |
PS1="${prompt}\$${COLOR_NONE} " | |
else | |
PS1="${prompt}${RED}\$${COLOR_NONE} " | |
fi | |
# ... | |
} | |
PROMPT_COMMAND=prompt_func | |
if [ ! "$color_prompt" = yes ]; then | |
PS1="${debian_chroot:+($debian_chroot)}\u@\h:\w:\$(parse_git_branch)\$ " | |
fi | |
unset color_prompt force_color_prompt | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* | |
export PATH="$PATH:$HOME/.rvm/bin" # Add RVM to PATH for scripting | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment