Created
May 27, 2016 20:53
-
-
Save nascimento/a559bc676b22d271591cc1760730b69f 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
### Start Piperita Theme ### | |
# Theme by Jacob Tomlinson | |
# https://github.com/killfall/terminal-piperita | |
# Aliases to make ls easier to use in different modes, taken from Red Hat EL 6 | |
alias ls='ls -GFh' | |
alias ll="ls -l" | |
alias lo="ls -o" | |
alias lh="ls -lh" | |
alias la="ls -la" | |
alias sl="ls" | |
alias grep="grep --color=auto" | |
# Set ls colors | |
export LSCOLORS=ExFxBxDxCxegedabagacad | |
# Alias to set color in grep | |
alias grep="grep --color=auto" | |
# Environment variables to set prompt format and color | |
export COLOR_BOLD="\[\e[1m\]" | |
export COLOR_DEFAULT="\[\e[0m\]" | |
export COLOR_WHITE="\[\033[m\]" | |
export COLOR_GREEN="\[\033[32m\]" | |
export COLOR_YELLOW="\[\033[33;1m\]" | |
export COLOR_RED="\[\e[31m\]" | |
export COLOR_BLUE="\[\033[36m\]" | |
# get current branch in git repo | |
function parse_git_branch() { | |
BRANCH=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') | |
if [ ! "${BRANCH}" == "" ] | |
then | |
STAT=$(parse_git_dirty) | |
echo -e " [${BRANCH}${STAT}]" | |
else | |
echo "" | |
fi | |
} | |
# get current status of git repo | |
function parse_git_dirty { | |
status=$(git status 2>&1 | tee) | |
dirty=$(echo -n "${status}" 2> /dev/null | grep "modified:" &> /dev/null; echo "$?") | |
untracked=$(echo -n "${status}" 2> /dev/null | grep "Untracked files" &> /dev/null; echo "$?") | |
ahead=$(echo -n "${status}" 2> /dev/null | grep "Your branch is ahead of" &> /dev/null; echo "$?") | |
newfile=$(echo -n "${status}" 2> /dev/null | grep "new file:" &> /dev/null; echo "$?") | |
renamed=$(echo -n "${status}" 2> /dev/null | grep "renamed:" &> /dev/null; echo "$?") | |
deleted=$(echo -n "${status}" 2> /dev/null | grep "deleted:" &> /dev/null; echo "$?") | |
bits='' | |
if [ "${renamed}" == "0" ]; then | |
bits=">${bits}" | |
fi | |
if [ "${ahead}" == "0" ]; then | |
bits="*${bits}" | |
fi | |
if [ "${newfile}" == "0" ]; then | |
bits="+${bits}" | |
fi | |
if [ "${untracked}" == "0" ]; then | |
bits="?${bits}" | |
fi | |
if [ "${deleted}" == "0" ]; then | |
bits="x${bits}" | |
fi | |
if [ "${dirty}" == "0" ]; then | |
bits="!${bits}" | |
fi | |
if [ ! "${bits}" == "" ]; then | |
echo " ${bits}" | |
else | |
echo "" | |
fi | |
} | |
prompt_cmd () { | |
LAST_STATUS=$? | |
PS1="" | |
# Test if user is root and set user color appropriately | |
if [[ $(id -u) == 0 ]] | |
then | |
PS1+="$COLOR_RED" | |
else | |
PS1+="$COLOR_BLUE" | |
fi | |
PS1+="\u" | |
PS1+="$COLOR_WHITE@" | |
PS1+="$COLOR_GREEN\h" | |
PS1+="$COLOR_WHITE:" | |
PS1+="$COLOR_YELLOW\W" | |
# Add git branch and status if applicable | |
if type parse_git_branch > /dev/null 2>&1; then | |
PS1+=$(parse_git_branch) | |
fi | |
# Test return code and colour the $ red if fail | |
if [[ $LAST_STATUS = 0 ]]; then | |
PS1+="$COLOR_WHITE" | |
else | |
PS1+="$COLOR_RED" | |
fi | |
PS1+='\$ ' | |
PS1+="$COLOR_WHITE" | |
} | |
PROMPT_COMMAND='prompt_cmd' | |
if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then | |
PROMPT_COMMAND="$PROMPT_COMMAND;update_terminal_cwd;" | |
fi | |
export CLICOLOR=1 | |
### End Piperita Theme ### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment