Skip to content

Instantly share code, notes, and snippets.

@JeanGoncalves
Last active September 25, 2015 18:46
Show Gist options
  • Select an option

  • Save JeanGoncalves/a05234fdd44ea3aab5a7 to your computer and use it in GitHub Desktop.

Select an option

Save JeanGoncalves/a05234fdd44ea3aab5a7 to your computer and use it in GitHub Desktop.
Bashrc personalization. Add these lines at the end of the .bashrc file.
#============================================================
# GENERAL CONFIGURATION
#============================================================
CONFIG_GIT_BRANCH_SHOW="true"
CONFIG_GIT_BRANCH_DELIMITERS[0]=""
CONFIG_GIT_BRANCH_DELIMITERS[1]=""
CONFIG_GIT_BRANCH_SHOW_ICON="true"
CONFIG_GIT_BRANCH_ICON_DELIMITERS[0]="["
CONFIG_GIT_BRANCH_ICON_DELIMITERS[1]=" ]"
CONFIG_GIT_FUNCTIONS_COLOR="true"
CONFIG_PS1_STYLE="5"
CONFIG_PS1_COLOR="true"
#------------------------------------------------------------
# Font colors
DEFAULT_COLOR=$(tput sgr0)
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
YELLOW=$(tput setaf 3)
BLUE=$(tput setaf 4)
BOLD_RED=$(tput bold; tput setaf 1)
BOLD_GREEN=$(tput bold; tput setaf 2)
BOLD_YELLOW=$(tput bold; tput setaf 3)
BOLD_BLUE=$(tput bold; tput setaf 4)
alias bash.reload="clear;. ~/.bashrc"
#------------------------------------------------------------
# Shows an icon informing whether the branch has changes.
#------------------------------------------------------------
git_branch_status() {
local icon=""
local icon_unchanged_branch="✔"
local icon_changed_branch="✖"
local branch_status=$(git status -s 2> /dev/null)
icon=${CONFIG_GIT_BRANCH_ICON_DELIMITERS[0]}$icon_unchanged_branch${CONFIG_GIT_BRANCH_ICON_DELIMITERS[1]}
if [ "$CONFIG_GIT_FUNCTIONS_COLOR" = "true" ]; then
icon="$BOLD_GREEN$icon$DEFAULT_COLOR"
fi
if [ "$branch_status" != "" ]; then
icon=${CONFIG_GIT_BRANCH_ICON_DELIMITERS[0]}$icon_changed_branch${CONFIG_GIT_BRANCH_ICON_DELIMITERS[1]}
if [ "$CONFIG_GIT_FUNCTIONS_COLOR" = "true" ]; then
icon="$BOLD_RED$icon$DEFAULT_COLOR"
fi
fi
echo $icon
}
#------------------------------------------------------------
# Shows the git branch name.
#------------------------------------------------------------
git_parse_branch() {
local branch_name=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')
local branch_full_info=""
if [ "$branch_name" != "" ] && [ "$CONFIG_GIT_BRANCH_SHOW" = "true" ]; then
if [ "$CONFIG_GIT_BRANCH_SHOW_ICON" = "true" ]; then
branch_name="$branch_name $(git_branch_status)"
fi
branch_full_info="$DEFAULT_COLOR${CONFIG_GIT_BRANCH_DELIMITERS[0]}$branch_name${CONFIG_GIT_BRANCH_DELIMITERS[1]}"
if [ "$CONFIG_GIT_FUNCTIONS_COLOR" = "true" ]; then
branch_full_info="$BOLD_BLUE${CONFIG_GIT_BRANCH_DELIMITERS[0]}$branch_name$BOLD_BLUE${CONFIG_GIT_BRANCH_DELIMITERS[1]}$DEFAULT_COLOR"
fi
if [ "$CONFIG_PS1_STYLE" = "1" ]; then
branch_full_info=$branch_full_info:" "
fi
fi
echo $branch_full_info
}
case $CONFIG_PS1_STYLE in
"2")
PS1="[\u]@[${HOSTNAME%%.*}]: \w \$(git_parse_branch) \n\\$ "
if [ "$CONFIG_PS1_COLOR" = "true" ]; then
PS1="$BOLD_RED[$BOLD_GREEN\u$BOLD_RED]$BOLD_YELLOW@$BOLD_RED[$BOLD_GREEN${HOSTNAME%%.*}$BOLD_RED]$BOLD_YELLOW:$BOLD_YELLOW \w $BOLD_BLUE\$(git_parse_branch) \n$BOLD_GREEN\\$ $DEFAULT_COLOR"
fi
;;
"3")
PS1="┌─[\h][\w] \\$ \$(git_parse_branch)\n└─╼ "
if [ "$CONFIG_PS1_COLOR" = "true" ]; then
PS1="$BOLD_RED┌─[$BOLD_GREEN\h$BOLD_RED][$BOLD_GREEN\w$BOLD_RED] $BOLD_YELLOW\\$ \$(git_parse_branch)\n$BOLD_RED└─╼ $DEFAULT_COLOR"
fi
;;
"4")
PS1="┌─[\u]──[${HOSTNAME%%.*}]: \w \\$ \$(git_parse_branch)\n└──>> "
if [ "$CONFIG_PS1_COLOR" = "true" ]; then
PS1="$BOLD_RED┌─[$BOLD_GREEN\u$BOLD_RED]──[$BOLD_GREEN${HOSTNAME%%.*}$BOLD_RED]: $BOLD_YELLOW\w \\$ \$(git_parse_branch)\n$BOLD_RED└──>> $DEFAULT_COLOR"
fi
;;
"5")
PS1="┌─ \u | ${HOSTNAME%%.*}: \w \\$ \$(git_parse_branch)\n└──> "
if [ "$CONFIG_PS1_COLOR" = "true" ]; then
PS1="$BOLD_RED┌─ $BOLD_GREEN\u$BOLD_RED | $BOLD_GREEN${HOSTNAME%%.*}$BOLD_RED : $BOLD_YELLOW\w \\$ \$(git_parse_branch)\n$BOLD_RED└──> $DEFAULT_COLOR"
fi
;;
*)
PS1="$PS1\$(git_parse_branch)"
if [ "$CONFIG_PS1_COLOR" = "true" ]; then
PS1="$BOLD_GREEN\u$BOLD_YELLOW@$BOLD_GREEN\h$BOLD_YELLOW\\$$DEFAULT_COLOR\$(git_parse_branch)"
fi
;;
esac
if [ -x /usr/bin/dircolors ]; then
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
alias ls='ls --color=auto'
fi
git_completions="~/scripts/git-completions.bash"
if [ -e $git_completions ]; then
. $git_completions
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment