Skip to content

Commit

Permalink
-git.ch: Upgrade code for new Git 2.20, also general uplift, shortening
Browse files Browse the repository at this point in the history
Issue #95
  • Loading branch information
psprint committed Dec 10, 2018
1 parent 8474cc3 commit 84e3094
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions chroma/-git.ch
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ else
__lines_list=( ${${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*}#alias.} )

if (( ${#__lines_list} > 0 )); then
# (*)
# First remove alias name (#*[[:space:]]) and the space after it, then
# remove any leading spaces from what's left (##[[:space:]]##), then
# remove everything except the first word that's in the left line
Expand All @@ -98,21 +99,33 @@ else
# Some further knowledge-base: s-flag is special, it skips
# empty elements and creates an array (not a concatenated
# string) even when double-quoted. The normally needed @-flag
# that breaks the concaetnated string back into array in case
# of double-quoting has additional effect for s-flag: it
# finally blocks empty-elements eradication.
__lines_list=( ${(M)${(s: :)${(M)__lines_list[@]:# [a-z]*}}:#$__wrd} )
# that logically breaks the concaetnated string back into array
# in case of double-quoting has additional effect for s-flag:
# it finally blocks empty-elements eradication.
if [[ "${__lines_list[1]}" = See* ]]; then
# (**)
# git >= v2.20
__lines_list=( ${(M)${${${(M)__lines_list[@]:# [[:blank:]]#[a-z]*}##[[:blank:]]##}%%[[:blank:]]##*}:#${FAST_HIGHLIGHT[chroma-git-subcommand]}} )
else
# (**)
# git < v2.20
__lines_list=( ${(M)${(s: :)${(M)__lines_list[@]:# [a-z]*}}:#${FAST_HIGHLIGHT[chroma-git-subcommand]}} )
fi

# Above we've checked:
# 1) If given subcommand is an alias (*)
# 2) If the command, or command pointed by the alias, exists (**)
# 3) There's little problem, git v2.20 outputs aliases in git help -a,
# which means that alias will be recognized as correct if it will
# point at another alias or on itself. That's a minor problem, a
# TODO for future planned optimization for v2.20 Git
# 4) Notice that the above situation is better than the previous - the
# alias is being verified to point to a valid git subcommand
# That's all that's needed to decide on the correctnes:
if (( ${#__lines_list} > 0 )); then
__style=${FAST_THEME_NAME}subcommand
else
-fast-run-command "git config --get-regexp 'alias.*'" chroma-git-alias-list "" 10
# Does a line match alias.{user-entered-subcmd}[[:space:]] ?
__lines_list=( ${(M)__lines_list[@]:#alias.${__wrd}[[:space:]]##*} )
if (( ${#__lines_list} > 0 )); then
__style=${FAST_THEME_NAME}subcommand
else
__style=${FAST_THEME_NAME}incorrect-subtle
fi
__style=${FAST_THEME_NAME}incorrect-subtle
fi
fi
# The counter includes the subcommand itself
Expand Down

0 comments on commit 84e3094

Please sign in to comment.