diff --git a/gitcrux.theme b/gitcrux.theme index 2813d2e..4a429b2 100644 --- a/gitcrux.theme +++ b/gitcrux.theme @@ -118,7 +118,7 @@ _gitcrux_VCS_header() { has_lines="+$lp_vcs_uncommitted_i_lines/-$lp_vcs_uncommitted_d_lines" fi fi - if [[ -n "$has_lines" ]]; then + if [[ "$has_lines" ]]; then head_stage="${LP_COLOR_DIFF}${has_lines}${NO_COL}" fi @@ -141,7 +141,7 @@ _gitcrux_VCS_header() { if _lp_vcs_head_status; then # NOTE: Replace the branch name. head_branch="[${LP_COLOR_CHANGES}${lp_vcs_head_status}" - if [[ -n "${lp_vcs_head_details-}" ]]; then + if [[ "${lp_vcs_head_details-}" ]]; then head_branch+=":${lp_vcs_head_details}" fi head_branch+="${NO_COL}]" @@ -171,10 +171,10 @@ _gitcrux_VCS_header() { GITCRUX_COL_WIDTH=$((GITCRUX_COL_WIDTH+1)) gitcrux_VCS_header="" - line="" + _GITCRUX_HEADER_LINE="" for col in "${head_remote}" "${head_repo}" "${head_stage}" "${head_branch}" "${head_stash}"; do _gitcrux_centered "│" $GITCRUX_COL_WIDTH - line+="$gitcrux_centered" + _GITCRUX_HEADER_LINE+="$gitcrux_centered" _gitcrux_centered "${col}" $GITCRUX_COL_WIDTH gitcrux_VCS_header+="$gitcrux_centered" @@ -182,11 +182,11 @@ _gitcrux_VCS_header() { } _gitcrux_VCS() { + local n=$'\n' _gitcrux_VCS_header - GITCRUX_VCS+="${gitcrux_VCS_header}${n}" - # GITCRUX_VCS+="${line}${n}" + # GITCRUX_VCS+="${_GITCRUX_HEADER_LINE}${n}" # Available states: # - $lp_vcs_commit_behind @@ -203,58 +203,58 @@ _gitcrux_VCS() { # - $lp_vcs_stash_count if [[ "$lp_vcs_type" != "git" ]]; then - _gitcrux_arrow "$line" "${GITCRUX_ARROW_RIGHT[0]}" "${GITCRUX_ARROW_LEFT[1]}" "${GITCRUX_COLOR_MSG}" 1 5 "Unsupported VCS, cannot provide hints" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" "${GITCRUX_ARROW_RIGHT[0]}" "${GITCRUX_ARROW_LEFT[1]}" "${GITCRUX_COLOR_MSG}" 1 5 "Unsupported VCS, cannot provide hints" GITCRUX_VCS+="${gitcrux_arrow}${n}" else # VCS is git if [[ "$lp_vcs_head_status" ]]; then if [[ "$lp_vcs_head_status" == *"REBASE"* ]]; then - _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add" GITCRUX_VCS+="${gitcrux_arrow}${n}" else # Unknown head status. - _gitcrux_arrow "$line" "${GITCRUX_ARROW_RIGHT[0]}" "${GITCRUX_ARROW_LEFT[1]}" "${GITCRUX_COLOR_MSG}" 1 5 "Unsupported head status, cannot provide hints" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" "${GITCRUX_ARROW_RIGHT[0]}" "${GITCRUX_ARROW_LEFT[1]}" "${GITCRUX_COLOR_MSG}" 1 5 "Unsupported head status, cannot provide hints" GITCRUX_VCS+="${gitcrux_arrow}${n}" fi else # No specific head status. if [[ "$lp_vcs_commit_behind" ]]; then if [[ "$has_lines" ]]; then - _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 183 1" 4 5 "save" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 183 1" 4 5 "save" GITCRUX_VCS+="${gitcrux_arrow}${n}" - _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" GITCRUX_VCS+="${gitcrux_arrow}${n}" - _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" GITCRUX_VCS+="${gitcrux_arrow}${n}" else # Do not have diff. if [[ "$lp_vcs_stash_count" ]]; then - _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" GITCRUX_VCS+="${gitcrux_arrow}${n}" - _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" GITCRUX_VCS+="${gitcrux_arrow}${n}" else # No stash. - _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" GITCRUX_VCS+="${gitcrux_arrow}${n}" fi fi else # No commit behind. if [[ "$has_lines" || "$lp_vcs_untracked_files" ]]; then - _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add" GITCRUX_VCS+="${gitcrux_arrow}${n}" - _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 202 1" 2 3 "commit" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 202 1" 2 3 "commit" GITCRUX_VCS+="${gitcrux_arrow}${n}" else # Do not have diff. if [[ "$lp_vcs_stash_count" ]]; then - _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" GITCRUX_VCS+="${gitcrux_arrow}${n}" else # Do not have stash. if [[ "$lp_vcs_commit_ahead" ]]; then - _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 220 1" 1 2 "push" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 220 1" 1 2 "push" GITCRUX_VCS+="${gitcrux_arrow}${n}" else # No commit ahead. if [[ "$head_branch" == *"master"* || "$head_branch" == *"main"* ]]; then - _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch" GITCRUX_VCS+="${gitcrux_arrow}${n}" fi # Main branch. fi # Commits ahead. @@ -265,37 +265,57 @@ _gitcrux_VCS() { fi # VCS is git. } +_gitcrux_remove_lp_escapes() { + gitcrux_remove_lp_escapes="$1" + gitcrux_remove_lp_escapes="${gitcrux_remove_lp_escapes//"$_LP_OPEN_ESC"}" + gitcrux_remove_lp_escapes="${gitcrux_remove_lp_escapes//"$_LP_CLOSE_ESC"}" +} + # Print the whole chart of hints. -# gitcrux() { -# _gitcrux_VCS_header -# ret="${gitcrux_VCS_header}${n}" +gitcrux() { + local n=$'\n' -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" -# ret+="${gitcrux_arrow}${n}" + _GITCRUX_HEAD_REPO="${PWD##*/}" -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch" -# ret+="${gitcrux_arrow}${n}" + _gitcrux_VCS_header + _gitcrux_remove_lp_escapes "${gitcrux_VCS_header}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 183 1" 4 5 "save" -# ret+="${gitcrux_arrow}${n}" + _gitcrux_remove_lp_escapes "${_GITCRUX_HEADER_LINE}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add" -# ret+="${gitcrux_arrow}${n}" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 202 1" 2 3 "commit" -# ret+="${gitcrux_arrow}${n}" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" -# ret+="${gitcrux_arrow}${n}" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 183 1" 4 5 "save" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 208 1" 2 4 "merge master" -# ret+="${gitcrux_arrow}${n}" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" -# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 220 1" 1 2 "push" -# ret+="${gitcrux_arrow}${n}" + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 202 1" 2 3 "commit" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" -# printf '%s' "$ret" -# } + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" + + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_RIGHT[@]} "0 208 1" 2 4 "merge master" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" + + _gitcrux_arrow "$_GITCRUX_HEADER_LINE" ${GITCRUX_ARROW_LEFT[@]} "0 220 1" 1 2 "push" + _gitcrux_remove_lp_escapes "${gitcrux_arrow}" + printf '%s' "${gitcrux_remove_lp_escapes}${n}" +} # This function is called when the prompt is activated,