From 5664084277b0426f92614705805b2eb5667b3542 Mon Sep 17 00:00:00 2001 From: Yehor Lvivski Date: Wed, 6 Nov 2013 22:30:54 +0200 Subject: [PATCH] remove useless curly brackets, add quotes to fix `git status` grep --- prompt.sh | 96 +++++++++++++++++++++++++++---------------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/prompt.sh b/prompt.sh index 009465a..e2723c2 100644 --- a/prompt.sh +++ b/prompt.sh @@ -43,10 +43,10 @@ function enrich { if [[ -n $3 ]]; then coloron=$3 else - coloron=${on} + coloron=$on fi - if [ ${use_color_off} == false -a ${flag} == false ]; then symbol=" "; fi - if [[ $flag == true ]]; then color="${coloron}"; else color="${off}"; fi + if [ $use_color_off == false -a $flag == false ]; then symbol=" "; fi + if [[ $flag == true ]]; then color=$coloron; else color=$off; fi PS1="${PS1}${color}${symbol}${reset} " } @@ -70,93 +70,93 @@ function build_prompt { git_status=$(git status --porcelain 2> /dev/null) - number_of_modifications=$(echo ${git_status} | grep --count -e ^\.M) - if [[ ${number_of_modifications} -gt 0 ]] ; then has_modifications=true; else has_modifications=false; fi + number_of_modifications=$(echo "$git_status" | grep --count -e ^\.M) + if [[ $number_of_modifications -gt 0 ]] ; then has_modifications=true; else has_modifications=false; fi - number_of_modifications_cached=$(echo ${git_status} | grep --count -e ^M) + number_of_modifications_cached=$(echo "$git_status" | grep --count -e ^M) if [[ ${number_of_modifications_cached} -gt 0 ]] ; then has_modifications_cached=true; else has_modifications_cached=false; fi - number_of_adds=$(echo ${git_status} | grep --count -e ^\A) - if [[ ${number_of_adds} -gt 0 ]] ; then has_adds=true; else has_adds=false; fi + number_of_adds=$(echo "$git_status" | grep --count -e ^\A) + if [[ $number_of_adds -gt 0 ]] ; then has_adds=true; else has_adds=false; fi - number_of_deletions=$(echo ${git_status} | grep --count -e ^.D) - if [[ ${number_of_deletions} -gt 0 ]] ; then has_deletions=true; else has_deletions=false; fi + number_of_deletions=$(echo "$git_status" | grep --count -e ^.D) + if [[ $number_of_deletions -gt 0 ]] ; then has_deletions=true; else has_deletions=false; fi - number_of_deletions_cached=$(echo ${git_status} | grep --count -e ^D) - if [[ ${number_of_deletions_cached} -gt 0 ]] ; then has_deletions_cached=true; else has_deletions_cached=false; fi + number_of_deletions_cached=$(echo "$git_status" | grep --count -e ^D) + if [[ $number_of_deletions_cached -gt 0 ]] ; then has_deletions_cached=true; else has_deletions_cached=false; fi - numbers_of_files_cached=$(echo ${git_status} | grep --count -e ^[MAD]) - numbers_of_files_not_cached=$(echo ${git_status} | grep --count -e ^.[MAD\?]) - if [ ${numbers_of_files_cached} -gt 0 -a ${numbers_of_files_not_cached} -eq 0 ] ; then ready_to_commit=true; else ready_to_commit=false; fi + numbers_of_files_cached=$(echo "$git_status" | grep --count -e ^[MAD]) + numbers_of_files_not_cached=$(echo "$git_status" | grep --count -e ^.[MAD\?]) + if [ $numbers_of_files_cached -gt 0 -a $numbers_of_files_not_cached -eq 0 ] ; then ready_to_commit=true; else ready_to_commit=false; fi - number_of_untracked_files=$(echo ${git_status} | grep --count -e ^\?\?) - if [[ ${number_of_untracked_files} -gt 0 ]] ; then has_untracked_files=true; else has_untracked_files=false; fi + number_of_untracked_files=$(echo "$git_status" | grep --count -e ^\?\?) + 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) - if [[ -n "${tag_at_current_commit}" ]]; then is_on_a_tag=true; else is_on_a_tag=false; fi + 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 has_diverged=false can_fast_forward=false commits_diff=$(git log --pretty=oneline --topo-order --left-right ${current_commit_hash}...${upstream} 2> /dev/null) - commits_ahead=$(echo ${commits_diff} | grep -c "^<" ) - commits_behind=$(echo ${commits_diff} | grep -c "^>" ) + commits_ahead=$(echo "$commits_diff" | grep -c "^<" ) + commits_behind=$(echo "$commits_diff" | grep -c "^>" ) - if [ ${commits_ahead} -gt 0 -a ${commits_behind} -gt 0 ]; then + if [ $commits_ahead -gt 0 -a $commits_behind -gt 0 ]; then has_diverged=true fi - if [ ${commits_ahead} -eq 0 -a ${commits_behind} -gt 0 ]; then + if [ $commits_ahead -eq 0 -a $commits_behind -gt 0 ]; then can_fast_forward=true fi will_rebase=$(git config --get branch.${current_branch}.rebase 2> /dev/null) number_of_stashes=$(git stash list | wc -l) - if [[ ${number_of_stashes} -gt 0 ]]; then has_stashes=true; else has_stashes=false; fi + if [[ $number_of_stashes -gt 0 ]]; then has_stashes=true; else has_stashes=false; fi else is_on_a_tag=false fi - if [[ ${is_a_git_repo} == true ]]; then - enrich ${is_a_git_repo} "${is_a_git_repo_symbol}" "${violet}" - enrich ${has_stashes} "${has_stashes_symbol}" "${yellow}" - enrich ${has_untracked_files} "${has_untracked_files_symbol}" "${red}" - enrich ${has_adds} "${has_adds_symbol}" "${yellow}" + if [[ $is_a_git_repo == true ]]; then + enrich $is_a_git_repo $is_a_git_repo_symbol $violet + enrich $has_stashes $has_stashes_symbol $yellow + enrich $has_untracked_files $has_untracked_files_symbol $red + enrich $has_adds $has_adds_symbol $yellow - enrich ${has_deletions} "${has_deletions_symbol}" "${red}" - enrich ${has_deletions_cached} "${has_deletions_cached_symbol}" "${yellow}" + enrich $has_deletions $has_deletions_symbol $red + enrich $has_deletions_cached $has_deletions_cached_symbol $yellow - enrich ${has_modifications} "${has_modifications_symbol}" "${red}" - enrich ${has_modifications_cached} "${has_modifications_cached_symbol}" "${yellow}" - enrich ${ready_to_commit} "${ready_to_commit_symbol}" "${green}" + enrich $has_modifications $has_modifications_symbol $red + enrich $has_modifications_cached $has_modifications_cached_symbol $yellow + enrich $ready_to_commit $ready_to_commit_symbol $green - enrich ${detached} "${detached_symbol}" "${red}" + enrich $detached $detached_symbol $red - if [[ ${display_has_upstream} == true ]]; then - enrich ${has_upstream} "${has_upstream_symbol}" + if [[ $display_has_upstream == true ]]; then + enrich $has_upstream $has_upstream_symbol fi - if [[ ${detached} == true ]]; then - if [[ ${just_init} == true ]]; then + if [[ $detached == true ]]; then + if [[ $just_init == true ]]; then PS1="${PS1}${red}detached" else PS1="${PS1}${on}(${current_commit_hash_abbrev})" fi else if [[ $has_upstream == true ]]; then - if [[ ${will_rebase} == true ]]; then - type_of_upstream="${rebase_tracking_branch_symbol}"; + if [[ $will_rebase == true ]]; then + type_of_upstream=$rebase_tracking_branch_symbol else - type_of_upstream="${merge_tracking_branch_symbol}"; + type_of_upstream=$merge_tracking_branch_symbol fi - if [[ ${has_diverged} == true ]]; then + if [[ $has_diverged == true ]]; then PS1="${PS1}-${commits_behind} ${has_diverged_symbol} +${commits_ahead} " else - if [[ ${commits_behind} -gt 0 ]]; then + if [[ $commits_behind -gt 0 ]]; then PS1="${PS1}${on} -${commits_behind} ${can_fast_forward_symbol} " fi - if [[ ${commits_ahead} -gt 0 ]]; then + if [[ $commits_ahead -gt 0 ]]; then PS1="${PS1}${on} ${should_push_symbol} +${commits_ahead} " fi fi @@ -166,15 +166,15 @@ function build_prompt { fi fi - if [[ ${display_tag} == true ]]; then + if [[ $display_tag == true ]]; then PS1="${PS1}${yellow}${is_on_a_tag_symbol}${reset}" fi - if [ ${display_tag_name} == true -a ${is_on_a_tag} == true ]; then + if [ $display_tag_name == true -a $is_on_a_tag == true ]; then PS1="${PS1}${yellow}[${tag_at_current_commit}]${reset}" fi fi - if [ ${two_lines} == true -a ${is_a_git_repo} == true ]; then + if [ $two_lines == true -a $is_a_git_repo == true ]; then break="\n"; else break="";