2013-09-02 02:31:05 -04:00
|
|
|
function enrich {
|
|
|
|
flag=$1
|
|
|
|
symbol=$2
|
2013-09-02 02:49:50 -04:00
|
|
|
|
|
|
|
if [[ $flag == true ]]; then color="${on}"; else color="${off}"; fi
|
2013-09-02 02:31:05 -04:00
|
|
|
PS1="${PS1}${color}${symbol} "
|
|
|
|
}
|
2013-09-01 18:59:21 -04:00
|
|
|
function enrich_if_not_null {
|
|
|
|
symbol=$1
|
|
|
|
variable=$2
|
2013-09-02 02:31:05 -04:00
|
|
|
flag=false
|
|
|
|
if [[ -n "$variable" ]]
|
2013-09-01 18:59:21 -04:00
|
|
|
then
|
2013-09-02 02:31:05 -04:00
|
|
|
flag="true"
|
2013-09-01 18:59:21 -04:00
|
|
|
else
|
2013-09-02 02:31:05 -04:00
|
|
|
flag="false"
|
2013-09-01 18:59:21 -04:00
|
|
|
fi
|
2013-09-02 02:31:05 -04:00
|
|
|
enrich "${flag}" "${symbol}"
|
2013-09-01 18:59:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function enrich_if_equal {
|
|
|
|
symbol=$1
|
|
|
|
variable=$2
|
|
|
|
condition=$3
|
|
|
|
if [[ $variable == "${condition}" ]]
|
|
|
|
then
|
2013-09-02 02:31:05 -04:00
|
|
|
flag="true"
|
2013-09-01 18:59:21 -04:00
|
|
|
else
|
2013-09-02 02:31:05 -04:00
|
|
|
flag="false"
|
2013-09-01 18:59:21 -04:00
|
|
|
fi
|
2013-09-02 02:31:05 -04:00
|
|
|
enrich "${flag}" "${symbol}"
|
2013-09-01 18:59:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
function enrich_if_greater_than_zero {
|
|
|
|
symbol=$1
|
|
|
|
variable=$2
|
|
|
|
if [[ $variable -gt 0 ]]
|
|
|
|
then
|
2013-09-02 02:31:05 -04:00
|
|
|
flag="true"
|
2013-09-01 18:59:21 -04:00
|
|
|
else
|
2013-09-02 02:31:05 -04:00
|
|
|
flag="false"
|
2013-09-01 18:59:21 -04:00
|
|
|
fi
|
2013-09-02 02:31:05 -04:00
|
|
|
enrich "${flag}" "${symbol}"
|
2013-09-01 18:59:21 -04:00
|
|
|
}
|
2013-09-02 02:31:05 -04:00
|
|
|
|
2013-09-01 18:02:16 -04:00
|
|
|
function build_prompt {
|
|
|
|
PS1=""
|
2013-09-02 02:49:50 -04:00
|
|
|
on="\[\033[0;37m\]"
|
2013-09-02 02:31:05 -04:00
|
|
|
off="\[\033[1;30m\]"
|
2013-09-02 02:49:50 -04:00
|
|
|
red="\[\033[0;31m\]"
|
2013-09-02 02:31:05 -04:00
|
|
|
branch_color="\[\033[0;34m\]"
|
2013-09-01 18:02:16 -04:00
|
|
|
blinking="\[\033[1;5;17m\]"
|
|
|
|
reset="\[\033[0m\]"
|
|
|
|
|
|
|
|
current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
|
2013-09-02 02:49:50 -04:00
|
|
|
if [[ -n "${current_branch}" ]]
|
|
|
|
then
|
|
|
|
is_a_git_repo=true
|
|
|
|
else
|
|
|
|
is_a_git_repo=false
|
|
|
|
fi
|
2013-09-01 18:59:21 -04:00
|
|
|
enrich_if_not_null "❤" $current_branch
|
|
|
|
enrich_if_equal "⚯" "${current_branch}" "HEAD"
|
2013-09-01 18:02:16 -04:00
|
|
|
|
2013-09-01 18:59:21 -04:00
|
|
|
number_of_modifications=$(git status --short 2> /dev/null|grep --count -e ^\.M)
|
2013-09-02 02:49:50 -04:00
|
|
|
if [[ ${number_of_modifications} -gt 0 ]] ; then has_modifications=true; else has_modifications=false; fi
|
|
|
|
enrich $has_modifications "✎"
|
2013-09-01 18:59:21 -04:00
|
|
|
|
|
|
|
number_of_modifications_cached=$(git status --short 2> /dev/null|grep --count -e ^M)
|
|
|
|
enrich_if_greater_than_zero "→" "${number_of_modifications_cached}"
|
|
|
|
|
|
|
|
number_of_untracked=$(git status --short 2> /dev/null|grep --count -e ^\?\?)
|
|
|
|
enrich_if_greater_than_zero "∿" "${number_of_untracked}"
|
2013-09-01 18:02:16 -04:00
|
|
|
|
2013-09-02 02:49:50 -04:00
|
|
|
if [[ ${is_a_git_repo} == true ]]
|
|
|
|
then
|
|
|
|
PS1="${PS1} ${on}(${current_branch})"
|
|
|
|
fi
|
2013-09-02 02:31:05 -04:00
|
|
|
PS1="${PS1}${reset} :"
|
2013-09-01 18:02:16 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#PREVIOUS_PROMPT=$PS1
|
|
|
|
PROMPT_COMMAND=build_prompt
|