From 2004174027b7ade5a1c6a45e27cf188ebb053f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Wed, 18 Aug 2021 12:17:14 -0500 Subject: Refactoring and improve git check most "eilf" were removed and replace for "case" --- hyperterm/core/git.sh | 209 ++++++++++++++++++++++----------------------- hyperterm/hyperterm.sha512 | 2 +- 2 files changed, 104 insertions(+), 107 deletions(-) diff --git a/hyperterm/core/git.sh b/hyperterm/core/git.sh index 55814dd..b6864e0 100644 --- a/hyperterm/core/git.sh +++ b/hyperterm/core/git.sh @@ -7,19 +7,20 @@ function _symbols() { _colors_bash "$@" _synced_symbol="$(printf '%b\u2714' "${BOLD}${CYAN}")" # ✔ - _dirty_synced_symbol="$(printf '%b\u002A' "${BOLD}${RED}")" # ∗ + _d_synced_symbol="$(printf '%b|%b\u002A' "${BOLD}${LEMON}" "${BOLD}${RED}")" # ∗ _unpushed_symbol="$(printf '%b\u2191' "${BOLD}${CYAN}")" # ↑ _dirty_unpushed_symbol="$(printf '%b\u25B2' "${BOLD}${YELLOW}")" # ▲ _unpulled_symbol="$(printf '%b\u25BD' "${BOLD}${GREEN}")" # ▽ _dirty_unpulled_symbol="$(printf '%b\u25BC' "${BOLD}${RED}")" # ▼ _stage_symbol="$(printf '%b\u2192\u004D' "${BOLD}${CYAN}")" # →M _unstage_symbol="$(printf '%b\u2190\u004D' "${BOLD}${RED}")" # ←M + _stage_unstage_symbol="$(printf '%b' "${BOLD}${RED}")" # _untracked_symbol="$(printf '%b\u003F' "${BOLD}${RED}")" # ? _newfile_symbol="$(printf '%b\u002B' "${BOLD}${CYAN}")" # + - _deleted_file_symbol="$(printf '%b\u2013' "${BOLD}${RED}")" # – + _deleted_file_symbol="$(printf '%bD' "${BOLD}${RED}")" # – _renamed_symbol="$(printf '%b\u2387 ' "${BOLD}${RED}")" # ⎇ _unpushed_unpulled_symbol="$(printf '%b\u2B21' "${BOLD}${RED}")" # ⬡ - _dirty_unpushed_unpulled_symbol="$(printf '%b\u2B22' "${BOLD}${RED}")" # ⬢ + _d_unpush_unpull_symbol="$(printf '%b|%bdu' "${BOLD}${LEMON}" "${BOLD}${CYAN}")" # du } function _get_git_branch() { @@ -101,11 +102,7 @@ _prompt_parse_git_ahead () { # If the remote branch is behind the local branch # or it has not been merged into origin (remote branch doesn't exist) - if (_prompt_is_branch1_behind_branch2 "$remote_branch" "$branch" || - ! _prompt_branch_exists "$remote_branch"); then - # printf our character - printf '%s' '0' - fi + if (_prompt_is_branch1_behind_branch2 "$remote_branch" "$branch" || ! _prompt_branch_exists "$remote_branch"); then echo -n "0"; else echo -n "1"; fi } _prompt_parse_git_behind() { @@ -122,17 +119,12 @@ _prompt_parse_git_behind() { # Unsynced commit # If the local branch is behind the remote branch - if _prompt_is_branch1_behind_branch2 "$branch" "$remote_branch"; then - # printf our character - printf '%s' '0' - fi + if _prompt_is_branch1_behind_branch2 "$branch" "$remote_branch"; then echo -n '0'; else echo -n '1'; fi } function _prompt_parse_git_dirty() { # If the git status has *any* changes (e.g. dirty), printf our character - if [[ -n "$(git status --porcelain 2> /dev/null)" ]]; then - printf '%s' '0' - fi + if [[ -n "$(git status --porcelain 2> /dev/null)" ]]; then echo -n '0'; else echo -n '1'; fi } # start counter on git @@ -144,17 +136,12 @@ function _git_dirty_count() { if [[ "$_dirty_status" == 0 ]]; then local change_count change_count="$(echo "$_git_status" | wc -l | tr -d '[:space:]')" - if [[ "$change_count" == 1 ]]; then - printf '%b\u2022%s' "${BOLD}${GREY}" "$change_count" - elif [[ "$change_count" == 2 ]]; then - printf '%b\u2236%s' "${BOLD}${GREY}" "$change_count" - elif [[ "$change_count" == 3 ]]; then - printf '%b\u2026%s' "${BOLD}${GREY}" "$change_count" - else - printf '%b\u00BB%s' "${BOLD}${GREY}" "$change_count" - fi - else - printf '' + case $change_count in + 1) printf '%b\u2022%s' "${BOLD}${GREY}" "$change_count";; + 2) printf '%b\u2236%s' "${BOLD}${GREY}" "$change_count";; + 3) printf '%b\u2026%s' "${BOLD}${GREY}" "$change_count";; + *) printf '%b\u00BB%s' "${BOLD}${GREY}" "$change_count";; + esac fi } # ends counter on git @@ -165,11 +152,7 @@ function _prompt_parse_git_untracked() { untracked="$(git status 2>&1 | tee)" grep -E 'Untracked files:' <<<"$untracked" &> /dev/null evaltask=$? - if [ "$evaltask" -eq 0 ]; then - printf '%s' '0' - else - printf '%s' '1' - fi + if [ "$evaltask" -eq 0 ]; then echo -n '0'; else echo -n '1'; fi } function _prompt_parse_git_newfile() { @@ -178,11 +161,7 @@ function _prompt_parse_git_newfile() { newfile="$(git status 2>&1 | tee)" grep -E 'new file:' <<<"$newfile" &> /dev/null evaltask=$? - if [ "$evaltask" -eq 0 ]; then - printf '%s' '0' - else - printf '%s' '1' - fi + if [ "$evaltask" -eq 0 ]; then echo -n '0'; else echo -n '1'; fi } function _prompt_parse_git_deleted_file() { @@ -191,11 +170,7 @@ function _prompt_parse_git_deleted_file() { deleted_file="$(git status 2>&1 | tee)" grep -E 'deleted:' <<<"$deleted_file" &> /dev/null evaltask=$? - if [ "$evaltask" -eq 0 ]; then - printf '%s' '0' - else - printf '%s' '1' - fi + if [ "$evaltask" -eq 0 ]; then echo -n '0'; else echo -n '1'; fi } function _prompt_parse_git_renamed() { @@ -204,11 +179,7 @@ function _prompt_parse_git_renamed() { renamed="$(git status 2>&1 | tee)" grep -E 'renamed:' <<<"$renamed" &> /dev/null evaltask=$? - if [ "$evaltask" -eq 0 ]; then - printf '%s' '0' - else - printf '%s' '1' - fi + if [ "$evaltask" -eq 0 ]; then echo -n '0'; else echo -n '1'; fi } function _prompt_parse_git_unstage() { @@ -217,11 +188,7 @@ function _prompt_parse_git_unstage() { unstage="$(git status 2>&1 | tee)" grep -E 'not staged' <<<"$unstage" &> /dev/null evaltask=$? - if [ "$evaltask" -eq 0 ]; then - printf '%s' '0' - else - printf '%s' '1' - fi + if [ "$evaltask" -eq 0 ]; then echo -n '0'; else echo -n '1'; fi } function _prompt_parse_git_stage() { @@ -230,11 +197,7 @@ function _prompt_parse_git_stage() { stage="$(git status -s 2>&1 | tee)" grep -E 'M' <<<"$stage" &> /dev/null evaltask=$? - if [ "$evaltask" -eq 0 ]; then - printf '%s' '0' - else - printf '%s' '1' - fi + if [ "$evaltask" -eq 0 ]; then echo -n '0'; else echo -n '1'; fi } function _prompt_is_on_git() { @@ -258,57 +221,91 @@ function _prompt_get_git_status() { branch_renamed="$(_prompt_parse_git_renamed)" # Iterate through all the cases and if it matches, then printf - if [[ "$dirty_branch" == 0 && "$branch_ahead" == 0 && "$branch_behind" == 0 ]]; then - printf '%s%s' "$_dirty_unpushed_unpulled_symbol" "$git_count" + case ${dirty_branch}${branch_ahead}${branch_behind}${branch_stage}${branch_unstage}${branch_newfile}${branch_untracked}${branch_deleted_file}${branch_renamed} in + + 000111111) printf '%s%s' "$_d_unpush_unpull_symbol" "$git_count" ;; + 100111111) printf '%s%s' "$_unpushed_unpulled_symbol" "$git_count" ;; + 001111111) printf '%s%s' "$_dirty_unpushed_symbol" "$git_count" ;; + 010111111) printf '%s%s' "$_dirty_unpulled_symbol" "$git_count" ;; + 110111111) printf '%s%s' "$_unpulled_symbol" "$git_count" ;; + + 011001111) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}" "$git_count";; + 011000111) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_newfile_symbol}" "$git_count";; + 011001101) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_deleted_file_symbol}" "$git_count";; + 011001011) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_untracked_symbol}" "$git_count" ;; + 011001001) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 011000101) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_deleted_file_symbol}" "$git_count";; + 011000001) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 011011111) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}" "$git_count";; + 011010111) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_newfile_symbol}" "$git_count";; + 011010101) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_newfile_symbol}${_deleted_file_symbol}" "$git_count" ;; + 011010001) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 011011011) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_untracked_symbol}" "$git_count";; + 011011101) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_deleted_file_symbol}" "$git_count";; + 011110111) printf '%s%s' "${_d_synced_symbol}${_newfile_symbol}" "$git_count";; + 011110011) printf '%s%s' "${_d_synced_symbol}${_newfile_symbol}${_untracked_symbol}" "$git_count";; + 011111011) printf '%s%s' "${_d_synced_symbol}${_untracked_symbol}" "$git_count";; + 011101001) printf '%s%s' "${_d_synced_symbol}${_unstage_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 011101001) printf '%s%s' "${_d_synced_symbol}${_unstage_symbol}${_deleted_file_symbol}" "$git_count";; + 011111110) printf '%s%s' "${_d_synced_symbol}${_renamed_symbol}" "$git_count";; + 011110110) printf '%s%s' "${_d_synced_symbol}${_newfile_symbol}${_renamed_symbol}" "$git_count";; + 011110010) printf '%s%s' "${_d_synced_symbol}${_newfile_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 011010100) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_newfile_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count" ;; + 011010000) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 011001010) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 011001000) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_untracked_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 011000110) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_renamed_symbol}" "$git_count";; + 011000010) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 011000000) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 011000100) printf '%s%s' "${_d_synced_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 011010010) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_newfile_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 011011010) printf '%s%s' "${_d_synced_symbol}${_stage_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 011111010) printf '%s%s' "${_d_synced_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + + 001001111) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}" "$git_count";; + 001000111) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_newfile_symbol}" "$git_count";; + 001001101) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_deleted_file_symbol}" "$git_count";; + 001001011) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_untracked_symbol}" "$git_count";; + 001001001) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 001000101) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_deleted_file_symbol}" "$git_count";; + 001000001) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 001011111) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}" "$git_count";; + 001010111) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_newfile_symbol}" "$git_count" ;; + 001010101) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_newfile_symbol}${_deleted_file_symbol}" "$git_count" ;; + 001010001) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 001011011) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_untracked_symbol}" "$git_count";; + 001011101) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_deleted_file_symbol}" "$git_count";; + 001110111) printf '%s%s' "${_d_unpush_unpull_symbol}${_newfile_symbol}" "$git_count";; + 001110011) printf '%s%s' "${_d_unpush_unpull_symbol}${_newfile_symbol}${_untracked_symbol}" "$git_count";; + 001111011) printf '%s%s' "${_d_unpush_unpull_symbol}${_untracked_symbol}" "$git_count";; + 001101001) printf '%s%s' "${_d_unpush_unpull_symbol}${_unstage_symbol}${_untracked_symbol}${_deleted_file_symbol}" "$git_count";; + 001101101) printf '%s%s' "${_d_unpush_unpull_symbol}${_unstage_symbol}${_deleted_file_symbol}" "$git_count";; + 001111110) printf '%s%s' "${_d_unpush_unpull_symbol}${_renamed_symbol}" "$git_count";; + 001110110) printf '%s%s' "${_d_unpush_unpull_symbol}${_newfile_symbol}${_renamed_symbol}" "$git_count";; + 001110010) printf '%s%s' "${_d_unpush_unpull_symbol}${_newfile_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 001010100) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_newfile_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count" ;; + 001010000) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 001001010) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 001001000) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_untracked_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 001000110) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_renamed_symbol}" "$git_count";; + 001000010) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 001000000) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_untracked_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 001000100) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_unstage_symbol}${_newfile_symbol}${_deleted_file_symbol}${_renamed_symbol}" "$git_count";; + 001010010) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_newfile_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 001011010) printf '%s%s' "${_d_unpush_unpull_symbol}${_stage_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + 001111010) printf '%s%s' "${_d_unpush_unpull_symbol}${_untracked_symbol}${_renamed_symbol}" "$git_count";; + + 101111111) printf '%s%s' "${_unpushed_symbol}" "$git_count" ;; # eg. ↑ + 111111111) printf '%s' "${_synced_symbol}" ;; # eg. ✔ + + *) echo -n "?" ;; + esac - elif [[ "$branch_ahead" == 0 && "$branch_behind" == 0 ]]; then - printf '%s%s' "$_unpushed_unpulled_symbol" "$git_count" - - elif [[ "$dirty_branch" == 0 && "$branch_ahead" == 0 ]]; then - printf '%s%s' "$_dirty_unpushed_symbol" "$git_count" - - elif [[ "$branch_ahead" == 0 ]]; then - printf '%s%s' "$_unpushed_symbol" "$git_count" - - elif [[ "$dirty_branch" == 0 && "$branch_behind" == 0 ]]; then - printf '%s%s' "$_dirty_unpulled_symbol" "$git_count" - - elif [[ "$branch_behind" == 0 ]]; then - printf '%s%s' "$_unpulled_symbol" "$git_count" - - elif [[ "$branch_unstage" == 0 && "$branch_untracked" == 0 ]]; then - printf '%s%s' "${_unstage_symbol}${_untracked_symbol}" "$git_count" - - elif [[ "$branch_stage" == 0 && "$branch_untracked" == 0 ]]; then - printf '%s%s' "${_stage_symbol}${_untracked_symbol}" "$git_count" - - elif [[ "$branch_stage" == 0 && "$branch_unstage" == 0 ]]; then - printf '%s%s' "$_unstage_symbol" "$git_count" - - elif [[ "$branch_newfile" == 0 && "$branch_untracked" == 0 ]]; then - printf '%s%s' "${_newfile_symbol}${_untracked_symbol}" "$git_count" - - elif [[ "$branch_untracked" == 0 ]]; then - printf '%s%s' "$_untracked_symbol" "$git_count" - - elif [[ "$branch_stage" == 0 ]]; then - printf '%s%s' "$_stage_symbol" "$git_count" - - elif [[ "$branch_newfile" == 0 ]]; then - printf '%s%s' "$_newfile_symbol" "$git_count" - - elif [[ "$branch_deleted_file" == 0 ]]; then - printf '%s%s' "$_deleted_file_symbol" "$git_count" - - elif [[ "$branch_renamed" == 0 ]]; then - printf '%s%s' "$_renamed_symbol" "$git_count" - - elif [[ "$dirty_branch" == 0 ]]; then - printf '%s%s' "$_dirty_synced_symbol" "$git_count" - - else # clean - printf '%s' "$_synced_symbol" - fi + # + # dirty + unpushed = du stage + unstage = + # ∗ ↑ ⬡ →M ←M + ? D ⎇ + # echo "${dirty_branch}${branch_ahead}${branch_behind}${branch_stage}${branch_unstage}${branch_newfile}${branch_untracked}${branch_deleted_file}${branch_renamed}" + # 0 0 1 1 0 1 1 0 1 } _prompt_get_git_info() { diff --git a/hyperterm/hyperterm.sha512 b/hyperterm/hyperterm.sha512 index 1c5d22d..73a98a1 100644 --- a/hyperterm/hyperterm.sha512 +++ b/hyperterm/hyperterm.sha512 @@ -13,7 +13,7 @@ fab9d339a99c7d2e1809d1c44f533523c6bfcdcc8d63c62b335ce7d4c666c8bdd7ac319316bf71f0 feff7e1dc5d3a84761495979eaf091dc2132fa081c3b4501756973a25e0514e9a00cc9a201767bac7d391eaee631777bbbd9bc032110e99da099c33f710a4c9f ./tools/network.sh 7447d3e167ab207d3ef4218e201a06bf5a3fc23281639f16f7f405f1d66b73923845d450fdb0a94672757866a9da0324f728564a1b61b2ed1678fe576eb565cf ./core/autocomplete.sh 065cfa39f1b4312ed275ad1039827a24f703176c653a8d27303d145f9d389a60ec5b3a9eb167e060cc6fd093b9c03cfb1a8b70254d444fbc6e62e2297d88b310 ./core/status.sh -2d3873cecaac498fa0d9d4d7e2aa9cda4b9063730f63fbf40eb03f14e6cde2d12e9a3a8b8bcf5eb9a663fabacf43b9b45fc2b3f23bc85cf29eea4e2fa824aa22 ./core/git.sh +7ec0f6b498207f64b736a4abf8134b547f8ed401f8d6f09d7c362537fbd9dd4c85cb258ce7317cd9287dd9caeb774f4467554844f542ce1b4ffb226797769034 ./core/git.sh 7aaec7140ce7b2f2a979ed5a0c7cf3e0a23584642780a161c9d015457d9960baedae14827afa9f3439a67dc98fc110f13114bcedfef5bc616dff79462b4f29b5 ./core/update.sh f3e00b2aa8ab9f3ab44570adaa2520408ed66fd00f551654d60b64a4be3546ec781b7efa39bcd774937e654b6ffb4c7af3f21eeb36caf9c01f82f85cf28e2b4d ./core/languages.sh 1cfba599047d84a17ff92b695ebf527a505a30acc9ec21a2b9f410a7ea6dde4b23b5cf62e557d82f2fe9a8980649942424b879ca53baae4d4cb3057681baa7b6 ./core/colors.sh -- cgit v1.2.3