From a48b0acabd56b12153103d2795f5ba0c678398b8 Mon Sep 17 00:00:00 2001 From: Arialdo Martini Date: Mon, 2 Sep 2013 23:27:36 +0200 Subject: [PATCH] Support for just initialized repositories --- prompt.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/prompt.sh b/prompt.sh index 04fb31d..1b6a75c 100644 --- a/prompt.sh +++ b/prompt.sh @@ -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}∙ " }