clean code
This commit is contained in:
parent
2d090fe9be
commit
f9cecd0864
1 changed files with 64 additions and 43 deletions
123
gitcrux.theme
123
gitcrux.theme
|
|
@ -2,8 +2,14 @@
|
|||
GITCRUX_ARROW_RIGHT=("" "")
|
||||
GITCRUX_ARROW_LEFT=("" "")
|
||||
|
||||
# bg fg
|
||||
GITCRUX_COLOR_REMOTE=(220 0)
|
||||
# fg bg bold
|
||||
GITCRUX_COLOR_WEAK="0 195 0"
|
||||
GITCRUX_COLOR_NORMAL="0 39 1"
|
||||
GITCRUX_COLOR_STRONG="0 220 1"
|
||||
GITCRUX_COLOR_MSG="0 244 0"
|
||||
|
||||
GITCRUX_COL_WIDTH=10
|
||||
GITCRUX_COL_DYNAMIC=1
|
||||
|
||||
# Center the given $1 text with spaces to fit a string of length $2.
|
||||
_gitcrux_centered() {
|
||||
|
|
@ -40,6 +46,7 @@ _gitcrux_centered() {
|
|||
|
||||
_gitcrux_arrow() {
|
||||
local in start end color from to text color_body color_ends
|
||||
gitcrux_arrow=""
|
||||
|
||||
in="$1"
|
||||
start="$2"
|
||||
|
|
@ -69,14 +76,14 @@ _gitcrux_arrow() {
|
|||
gitcrux_arrow="${in:0:from}${color_ends}${start}${color_body}${gitcrux_centered}${color_ends}${end}${NO_COL}${in:to:${#in}}"
|
||||
}
|
||||
|
||||
_gitcrux_VCS() {
|
||||
GITCRUX_COL_WIDTH=0
|
||||
_gitcrux_VCS_header() {
|
||||
GITCRUX_VCS=""
|
||||
|
||||
local head_remote head_repo head_stage head_branch
|
||||
local head_remote= head_repo= head_stage= head_branch=
|
||||
local has_lines
|
||||
|
||||
# REMOTE
|
||||
head_remote="origin" # TODO
|
||||
head_remote="remote" # TODO
|
||||
|
||||
# REPO
|
||||
head_repo="${_GITCRUX_HEAD_REPO}"
|
||||
|
|
@ -94,8 +101,8 @@ _gitcrux_VCS() {
|
|||
# STAGE
|
||||
LP_TIME_ANALOG=1
|
||||
_lp_analog_time
|
||||
# head_stage="$lp_analog_time"
|
||||
head_stage="STAGE"
|
||||
head_stage="$lp_analog_time"
|
||||
# head_stage="STAGE"
|
||||
|
||||
local ret has_lines=
|
||||
if _lp_vcs_uncommitted_files; then
|
||||
|
|
@ -141,7 +148,7 @@ _gitcrux_VCS() {
|
|||
fi
|
||||
|
||||
if _lp_vcs_untracked_files; then
|
||||
head_branch+="(${LP_COLOR_CHANGES}${lp_vcs_untracked_files}${NO_COL})"
|
||||
head_branch+="(${LP_COLOR_CHANGES}${lp_vcs_untracked_files}${NO_COL})"
|
||||
fi
|
||||
|
||||
# STASH
|
||||
|
|
@ -151,9 +158,8 @@ _gitcrux_VCS() {
|
|||
head_stash+="(${LP_COLOR_COMMITS}${lp_vcs_stash_count})"
|
||||
fi
|
||||
|
||||
|
||||
# ARROWS
|
||||
if [[ "$GITCRUX_COL_WIDTH" -eq "0" ]]; then
|
||||
# COLUMNS
|
||||
if [[ "$GITCRUX_COL_DYNAMIC" ]]; then
|
||||
for col in "${head_remote}" "${head_repo}" "${head_stage}" "${head_branch}" "${head_stash}"; do
|
||||
if (( ${#col} > GITCRUX_COL_WIDTH )); then
|
||||
__lp_strip_escapes "${col}"
|
||||
|
|
@ -164,18 +170,22 @@ _gitcrux_VCS() {
|
|||
# At least some spacing.
|
||||
GITCRUX_COL_WIDTH=$((GITCRUX_COL_WIDTH+1))
|
||||
|
||||
header=""
|
||||
gitcrux_VCS_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_centered "${col}" $GITCRUX_COL_WIDTH
|
||||
header+="$gitcrux_centered"
|
||||
gitcrux_VCS_header+="$gitcrux_centered"
|
||||
done
|
||||
}
|
||||
|
||||
_gitcrux_VCS() {
|
||||
|
||||
GITCRUX_VCS+="${header}${n}"
|
||||
_gitcrux_VCS_header
|
||||
|
||||
GITCRUX_VCS+="${gitcrux_VCS_header}${n}"
|
||||
# GITCRUX_VCS+="${line}${n}"
|
||||
|
||||
# Available states:
|
||||
|
|
@ -193,14 +203,16 @@ _gitcrux_VCS() {
|
|||
# - $lp_vcs_stash_count
|
||||
|
||||
if [[ "$lp_vcs_type" != "git" ]]; then
|
||||
GITCRUX_VCS+="[Unsupported VCS, cannot provide hints.]${n}"
|
||||
_gitcrux_arrow "$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_VCS+="${gitcrux_arrow}${n}"
|
||||
else # Unknown head status.
|
||||
GITCRUX_VCS+="[Unsupported head status, cannot provide hints.]${n}"
|
||||
_gitcrux_arrow "$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
|
||||
|
|
@ -226,7 +238,7 @@ _gitcrux_VCS() {
|
|||
fi
|
||||
fi
|
||||
else # No commit behind.
|
||||
if [[ "$has_lines" ]]; then
|
||||
if [[ "$has_lines" || "$lp_vcs_untracked_files" ]]; then
|
||||
_gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add"
|
||||
GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
|
|
@ -241,41 +253,50 @@ _gitcrux_VCS() {
|
|||
_gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 220 1" 1 2 "push"
|
||||
GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
else # No commit ahead.
|
||||
_gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch"
|
||||
GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull"
|
||||
# GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch"
|
||||
# GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 183 1" 4 5 "save"
|
||||
# GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$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_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop"
|
||||
# GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 208 1" 2 4 "merge master"
|
||||
# GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 220 1" 1 2 "push"
|
||||
# GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
|
||||
if [[ "$head_branch" == *"master"* || "$head_branch" == *"main"* ]]; then
|
||||
_gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch"
|
||||
GITCRUX_VCS+="${gitcrux_arrow}${n}"
|
||||
fi # Main branch.
|
||||
fi # Commits ahead.
|
||||
fi # Stash.
|
||||
fi # Has lines or untracked files.
|
||||
fi # Commits behind.
|
||||
fi # Head status.
|
||||
fi # VCS is git.
|
||||
}
|
||||
|
||||
# Print the whole chart of hints.
|
||||
# gitcrux() {
|
||||
# _gitcrux_VCS_header
|
||||
# ret="${gitcrux_VCS_header}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 220 1" 1 4 "pull"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 45 1" 2 4 "branch"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 183 1" 4 5 "save"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 46 1" 3 4 "add"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 202 1" 2 3 "commit"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 183 1" 4 5 "pop"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_RIGHT[@]} "0 208 1" 2 4 "merge master"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# _gitcrux_arrow "$line" ${GITCRUX_ARROW_LEFT[@]} "0 220 1" 1 2 "push"
|
||||
# ret+="${gitcrux_arrow}${n}"
|
||||
|
||||
# printf '%s' "$ret"
|
||||
# }
|
||||
|
||||
|
||||
# This function is called when the prompt is activated,
|
||||
# either at the very beginning of the shell session,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue