Support for just initialized repositories
This commit is contained in:
parent
694e1f854e
commit
a48b0acabd
23
prompt.sh
23
prompt.sh
@ -25,10 +25,16 @@ function build_prompt {
|
|||||||
current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
|
current_commit_hash=$(git rev-parse HEAD 2> /dev/null)
|
||||||
current_commit_hash_abbrev=$(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
|
||||||
|
|
||||||
if [[ $is_a_git_repo == true ]]; then
|
number_of_logs=$(git log 2>/dev/null| wc -l)
|
||||||
current_branch=$(git rev-parse --abbrev-ref HEAD);
|
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null);
|
||||||
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 -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
|
||||||
|
|
||||||
@ -63,6 +69,7 @@ function build_prompt {
|
|||||||
# echo "Has untracked files: ${has_untracked_files}"
|
# echo "Has untracked files: ${has_untracked_files}"
|
||||||
# echo "Has deletions: ${has_deletions}"
|
# echo "Has deletions: ${has_deletions}"
|
||||||
# echo "Has adds: ${has_adds}"
|
# echo "Has adds: ${has_adds}"
|
||||||
|
#echo "Just init: ${just_init}"
|
||||||
|
|
||||||
if [[ ${is_a_git_repo} == true ]]
|
if [[ ${is_a_git_repo} == true ]]
|
||||||
then
|
then
|
||||||
@ -78,7 +85,11 @@ function build_prompt {
|
|||||||
|
|
||||||
if [[ ${detached} == true ]]
|
if [[ ${detached} == true ]]
|
||||||
then
|
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
|
else
|
||||||
if [[ $has_upstream == true ]]
|
if [[ $has_upstream == true ]]
|
||||||
then
|
then
|
||||||
@ -89,7 +100,7 @@ function build_prompt {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
fi
|
fi
|
||||||
PS1="${PS1}${reset}${PREVIOUS_PS1}"
|
PS1="${PS1}${reset}∙ "
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user