Fix indentation

This commit is contained in:
Yehor Lvivski 2013-09-23 17:35:34 +03:00
parent 47d59a0d81
commit 4cc7e60f70

View File

@ -1,8 +1,7 @@
function enrich { function enrich {
flag=$1 flag=$1
symbol=$2 symbol=$2
if [[ -n $3 ]] if [[ -n $3 ]]; then
then
coloron=$3 coloron=$3
else else
coloron=${on} coloron=${on}
@ -14,6 +13,7 @@ function enrich {
function build_prompt { function build_prompt {
PS1="" PS1=""
# Symbols # Symbols
if [[ -z "${is_a_git_repo_symbol}" ]]; then is_a_git_repo_symbol="❤"; fi if [[ -z "${is_a_git_repo_symbol}" ]]; then is_a_git_repo_symbol="❤"; fi
if [[ -z "${has_untracked_files_symbol}" ]]; then has_untracked_files_symbol="∿"; fi if [[ -z "${has_untracked_files_symbol}" ]]; then has_untracked_files_symbol="∿"; fi
@ -34,8 +34,7 @@ function build_prompt {
if [[ -z "${should_push_symbol}" ]]; then should_push_symbol="↑"; fi if [[ -z "${should_push_symbol}" ]]; then should_push_symbol="↑"; fi
if [[ -z "${has_stashes_symbol}" ]]; then has_stashes_symbol="★"; fi if [[ -z "${has_stashes_symbol}" ]]; then has_stashes_symbol="★"; fi
# Flags
# flags
if [[ -z "${display_has_upstream}" ]]; then display_has_upstream=false; fi if [[ -z "${display_has_upstream}" ]]; then display_has_upstream=false; fi
if [[ -z "${display_tag}" ]]; then display_tag=false; fi if [[ -z "${display_tag}" ]]; then display_tag=false; fi
if [[ -z "${display_tag_name}" ]]; then display_tag_name=true; fi if [[ -z "${display_tag_name}" ]]; then display_tag_name=true; fi
@ -64,15 +63,14 @@ function build_prompt {
if [[ $current_branch == "HEAD" ]]; then detached=true; else detached=false; fi if [[ $current_branch == "HEAD" ]]; then detached=true; else detached=false; fi
if [ $is_a_git_repo == true -a $number_of_logs == 0 ]; then just_init=true; fi if [ $is_a_git_repo == true -a $number_of_logs == 0 ]; then just_init=true; fi
if [ $is_a_git_repo == true -a $number_of_logs -gt 0 ]; then if [ $is_a_git_repo == true -a $number_of_logs -gt 0 ]; then
upstream=$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} 2> /dev/null) upstream=$(git rev-parse --symbolic-full-name --abbrev-ref @{upstream} 2> /dev/null)
if [[ $upstream != "@{upstream}" ]]; then has_upstream=true; else has_upstream=false; upstream=""; fi if [[ $upstream != "@{upstream}" ]]; then has_upstream=true; else has_upstream=false; upstream=""; fi
number_of_modifications=$(git status --short 2> /dev/null|grep --count -e ^\.M) number_of_modifications=$(git status --short 2> /dev/null|grep --count -e ^\.M)
if [[ ${number_of_modifications} -gt 0 ]] ; then has_modifications=true; else has_modifications=false; fi if [[ ${number_of_modifications} -gt 0 ]] ; then has_modifications=true; else has_modifications=false; fi
number_of_modifications_cached=$(git status --short 2> /dev/null|grep --count -e ^M) number_of_modifications_cached=$(git status --short 2> /dev/null|grep --count -e ^M)
if [[ ${number_of_modifications_cached} -gt 0 ]] ; then has_modifications_cached=true; else has_modifications_cached=false; fi if [[ ${number_of_modifications_cached} -gt 0 ]] ; then has_modifications_cached=true; else has_modifications_cached=false; fi
@ -81,6 +79,7 @@ function build_prompt {
number_of_deletions=$(git status --short 2> /dev/null|grep --count -e ^.D) number_of_deletions=$(git status --short 2> /dev/null|grep --count -e ^.D)
if [[ ${number_of_deletions} -gt 0 ]] ; then has_deletions=true; else has_deletions=false; fi if [[ ${number_of_deletions} -gt 0 ]] ; then has_deletions=true; else has_deletions=false; fi
number_of_deletions_cached=$(git status --short 2> /dev/null|grep --count -e ^D) number_of_deletions_cached=$(git status --short 2> /dev/null|grep --count -e ^D)
if [[ ${number_of_deletions_cached} -gt 0 ]] ; then has_deletions_cached=true; else has_deletions_cached=false; fi if [[ ${number_of_deletions_cached} -gt 0 ]] ; then has_deletions_cached=true; else has_deletions_cached=false; fi
@ -92,8 +91,7 @@ function build_prompt {
if [[ ${number_of_untracked_files} -gt 0 ]] ; then has_untracked_files=true; else has_untracked_files=false; fi if [[ ${number_of_untracked_files} -gt 0 ]] ; then has_untracked_files=true; else has_untracked_files=false; fi
tag_at_current_commit=$(git describe --exact-match --tags ${current_commit_hash} 2>/dev/null) tag_at_current_commit=$(git describe --exact-match --tags ${current_commit_hash} 2>/dev/null)
if [[ -n "${tag_at_current_commit}" ]]; then is_on_a_tag=true; else is_on_a_tag=false; fi
if [[ -n "${tag_at_current_commit}" ]]; then is_on_a_tag=true; else is_on_a_tag=false; fi;
commits_ahead=0 commits_ahead=0
commits_behind=0 commits_behind=0
@ -104,12 +102,10 @@ function build_prompt {
commits_ahead=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^<" ) commits_ahead=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^<" )
commits_behind=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^>" ) commits_behind=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} | grep -c "^>" )
if [ ${commits_ahead} -gt 0 -a ${commits_behind} -gt 0 ]; if [ ${commits_ahead} -gt 0 -a ${commits_behind} -gt 0 ]; then
then
has_diverged=true has_diverged=true
fi fi
if [ ${commits_ahead} -eq 0 -a ${commits_behind} -gt 0 ]; if [ ${commits_ahead} -eq 0 -a ${commits_behind} -gt 0 ]; then
then
can_fast_forward=true can_fast_forward=true
fi fi
@ -121,8 +117,7 @@ function build_prompt {
is_on_a_tag=false is_on_a_tag=false
fi fi
if [[ ${is_a_git_repo} == true ]] if [[ ${is_a_git_repo} == true ]]; then
then
enrich ${is_a_git_repo} "${is_a_git_repo_symbol}" "${violet}" enrich ${is_a_git_repo} "${is_a_git_repo_symbol}" "${violet}"
enrich ${has_stashes} "${has_stashes_symbol}" "${yellow}" enrich ${has_stashes} "${has_stashes_symbol}" "${yellow}"
enrich ${has_untracked_files} "${has_untracked_files_symbol}" "${red}" enrich ${has_untracked_files} "${has_untracked_files_symbol}" "${red}"
@ -140,38 +135,30 @@ function build_prompt {
if [[ ${display_has_upstream} == true ]]; then if [[ ${display_has_upstream} == true ]]; then
enrich ${has_upstream} "${has_upstream_symbol}" enrich ${has_upstream} "${has_upstream_symbol}"
fi fi
if [[ ${detached} == true ]] if [[ ${detached} == true ]]; then
then
if [[ ${just_init} == true ]]; then if [[ ${just_init} == true ]]; then
PS1="${PS1} ${red}detached" PS1="${PS1} ${red}detached"
else else
PS1="${PS1} ${on}(${current_commit_hash_abbrev})" PS1="${PS1} ${on}(${current_commit_hash_abbrev})"
fi fi
else else
if [[ $has_upstream == true ]] if [[ $has_upstream == true ]]; then
then if [[ ${will_rebase} == true ]]; then
if [[ ${will_rebase} == true ]];
then
type_of_upstream="${rebase_tracking_branch_symbol}"; type_of_upstream="${rebase_tracking_branch_symbol}";
else else
type_of_upstream="${merge_tracking_branch_symbol}"; type_of_upstream="${merge_tracking_branch_symbol}";
fi fi
if [[ ${has_diverged} == true ]]; then if [[ ${has_diverged} == true ]]; then
PS1="${PS1} -${commits_behind} ${has_diverged_symbol} +${commits_ahead}" PS1="${PS1} -${commits_behind} ${has_diverged_symbol} +${commits_ahead}"
else else
if [[ ${commits_behind} -gt 0 ]]; then if [[ ${commits_behind} -gt 0 ]]; then
PS1="${PS1} ${on} -${commits_behind} ${can_fast_forward_symbol} " PS1="${PS1} ${on} -${commits_behind} ${can_fast_forward_symbol} "
fi fi
if [[ ${commits_ahead} -gt 0 ]]; then if [[ ${commits_ahead} -gt 0 ]]; then
PS1="${PS1} ${on} ${should_push_symbol} +${commits_ahead}" PS1="${PS1} ${on} ${should_push_symbol} +${commits_ahead}"
fi fi
fi fi
PS1="${PS1} (${green}${current_branch}${reset} ${type_of_upstream} ${upstream//\/$current_branch/})" PS1="${PS1} (${green}${current_branch}${reset} ${type_of_upstream} ${upstream//\/$current_branch/})"
else else
PS1="${PS1} ${on}(${green}${current_branch}${reset})" PS1="${PS1} ${on}(${green}${current_branch}${reset})"
@ -181,22 +168,18 @@ function build_prompt {
if [[ ${display_tag} == true ]]; then if [[ ${display_tag} == true ]]; then
PS1="${PS1} ${yellow}${is_on_a_tag_symbol}${reset}" PS1="${PS1} ${yellow}${is_on_a_tag_symbol}${reset}"
fi fi
if [ ${display_tag_name} == true -a ${is_on_a_tag} == true ]; if [ ${display_tag_name} == true -a ${is_on_a_tag} == true ]; then
then
PS1="${PS1} ${yellow}[${tag_at_current_commit}]${reset}" PS1="${PS1} ${yellow}[${tag_at_current_commit}]${reset}"
fi fi
fi fi
if [ ${two_lines} == true -a ${is_a_git_repo} == true ]; if [ ${two_lines} == true -a ${is_a_git_repo} == true ]; then
then
break="\n"; break="\n";
else else
break=""; break="";
fi fi
PS1="${PS1}${reset}${break}${finally}" PS1="${PS1}${reset}${break}${finally}"
} }
PROMPT_COMMAND=build_prompt PROMPT_COMMAND=build_prompt