move branch detection inside condition, remove extra hash detection
This commit is contained in:
parent
bf48ddc00b
commit
1d0a1a058c
11
prompt.sh
11
prompt.sh
@ -54,17 +54,16 @@ function build_prompt {
|
|||||||
PS1=""
|
PS1=""
|
||||||
|
|
||||||
# Git info
|
# Git info
|
||||||
current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
|
current_commit_hash=$(git rev-parse --short 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 [[ -n $current_commit_hash ]]; then is_a_git_repo=true; else is_a_git_repo=false; fi
|
||||||
|
|
||||||
number_of_logs=$(git log --pretty=oneline 2> /dev/null | wc -l)
|
number_of_logs=$(git log --pretty=oneline 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 && $number_of_logs == 0 ]]; then just_init=true; fi
|
if [[ $is_a_git_repo == true && $number_of_logs == 0 ]]; then just_init=true; fi
|
||||||
if [[ $is_a_git_repo == true && $number_of_logs -gt 0 ]]; then
|
if [[ $is_a_git_repo == true && $number_of_logs -gt 0 ]]; then
|
||||||
|
current_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
|
||||||
|
if [[ $current_branch == 'HEAD' ]]; then detached=true; else detached=false; fi
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
@ -140,7 +139,7 @@ function build_prompt {
|
|||||||
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})"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ $has_upstream == true ]]; then
|
if [[ $has_upstream == true ]]; then
|
||||||
|
Loading…
x
Reference in New Issue
Block a user