Support for just initialized repositories

This commit is contained in:
Arialdo Martini 2013-09-02 23:27:36 +02:00
parent 694e1f854e
commit a48b0acabd

View File

@ -25,10 +25,16 @@ function build_prompt {
current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
current_commit_hash_abbrev=$(git rev-parse --short HEAD 2> /dev/null)
if [[ -n $current_commit_hash ]]; then is_a_git_repo=true; else is_a_git_repo=false; fi
if [[ $is_a_git_repo == true ]]; then
current_branch=$(git rev-parse --abbrev-ref HEAD);
if [[ $current_branch == "HEAD" ]]; then detached=true; else detached=false; fi
number_of_logs=$(git log 2>/dev/null| wc -l)
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null);
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 -gt 0 ]; then
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
@ -63,6 +69,7 @@ function build_prompt {
# echo "Has untracked files: ${has_untracked_files}"
# echo "Has deletions: ${has_deletions}"
# echo "Has adds: ${has_adds}"
#echo "Just init: ${just_init}"
if [[ ${is_a_git_repo} == true ]]
then
@ -78,7 +85,11 @@ function build_prompt {
if [[ ${detached} == true ]]
then
PS1="${PS1} ${on}($current_commit_hash_abbrev)"
if [[ ${just_init} == true ]]; then
PS1="${PS1} ${alert}detached"
else
PS1="${PS1} ${on}($current_commit_hash_abbrev)"
fi
else
if [[ $has_upstream == true ]]
then
@ -89,7 +100,7 @@ function build_prompt {
fi
fi
PS1="${PS1}${reset}${PREVIOUS_PS1}"
PS1="${PS1}${reset}"
}