Skip to content

Commit

Permalink
fix pre_expand when no correction
Browse files Browse the repository at this point in the history
  • Loading branch information
MenkeTechnologies committed Dec 24, 2021
1 parent 5f688f6 commit daa988c
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 45 deletions.
3 changes: 1 addition & 2 deletions zpwrExpandApi.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@ function zpwrExpandLastWordAtCommandPosAndExpand(){
fi
else
# here if not called by supernatural space fn
if [[ "$ZPWR_EXPAND_WORDS_LPARTITION" =~ "$ZPWR_VARS[continueFirstPositionRegex]" ]];then
ZPWR_EXPAND_PRE_EXPAND=("${(z)match[-1]}")
if zpwrExpandRegexMatchOnCommandPosition; then

if (( $#ZPWR_EXPAND_PRE_EXPAND == 1)); then
if [[ $caller == zle ]]; then
Expand Down
100 changes: 57 additions & 43 deletions zpwrExpandLib.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ function zpwrExpandCorrectWord(){
fi
else

if [[ "$ZPWR_EXPAND_WORDS_LPARTITION" =~ "$ZPWR_VARS[continueFirstPositionRegexNoZpwr]" ]];then
ZPWR_EXPAND_PRE_CORRECT=("${(z)match[-1]}")
if zpwrExpandRegexMatchOnCommandPosition correct; then

#zpwrLogDebug "${match[@]}"
#zpwrLogDebug "${ZPWR_EXPAND_PRE_CORRECT[@]}"
Expand Down Expand Up @@ -211,6 +210,52 @@ function zpwrExpandRightTrim() {

}

zpwrExpandTerminateSpace(){

LBUFFER+=" "
}

function zpwrExpandNonFileExpansion(){
:
#DNS lookups
#type -a "$lastWord" &> /dev/null || {
#print -r -- $lastWord | command grep -qE \
#'^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\.?$'\
#&& {
##DNS lookup
#A_Record=$(host $lastWord) 2>/dev/null \
#&& {
#A_Record=$(print -r -- $A_Record | command grep ' address' | head -1 | awk '{print $4}')
#} || A_Record=bad
#[[ $A_Record != bad ]] && \
#LBUFFER="$(print -r -- "$LBUFFER" | sed -E "s@\\b$lastWord@$A_Record@g")"
#} || {
#print -r -- $lastWord | command grep -qE \
#'\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' && {
##reverse DNS lookup
#PTR_Record=$(nslookup $lastWord) 2>/dev/null && {
#PTR_Record=$(print -r -- $PTR_Record | command grep 'name = ' | tail -1 | awk '{print $4}')
#} || PTR_Record=bad
#[[ $PTR_Record != bad ]] && \
#LBUFFER="$(print -r -- "$LBUFFER" | sed -E "s@\\b$lastWord\\b@${PTR_Record:0:-1}@g")"
#}
#}
#}
}

function zpwrExpandRegexMatchOnCommandPosition() {

if [[ "$ZPWR_EXPAND_WORDS_LPARTITION" =~ "$ZPWR_VARS[continueFirstPositionRegexNoZpwr]" ]];then
if [[ $1 == "correct" ]]; then
ZPWR_EXPAND_PRE_CORRECT=("${(z)match[-1]}")
else
ZPWR_EXPAND_PRE_EXPAND=("${(z)match[-1]}")
fi
return 0
fi
return 1
}

#}}}***********************************************************

#{{{ MARK:main fn
Expand Down Expand Up @@ -241,17 +286,19 @@ function zpwrExpandSupernaturalSpace() {
if [[ $triggerKey == "${ZPWR_VARS[SPACE_KEY]}" ]]; then
if [[ $ZPWR_CORRECT == true ]]; then
zpwrExpandCorrectWord
fi

if [[ $ZPWR_VARS[foundIncorrect] = true && $ZPWR_CORRECT_EXPAND = true ]]; then
#zpwrLogDebug "RE-EXPAND after incorrect spelling"
ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_POST_CORRECT[@]}" )
zpwrExpandParseWords "$LBUFFER"
if [[ $ZPWR_VARS[foundIncorrect] = true && $ZPWR_CORRECT_EXPAND = true ]]; then
#zpwrLogDebug "RE-EXPAND after incorrect spelling"
ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_POST_CORRECT[@]}" )
zpwrExpandParseWords "$LBUFFER"
else
ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_PRE_CORRECT[@]}" )
fi
else
ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_PRE_CORRECT[@]}" )
zpwrExpandRegexMatchOnCommandPosition
fi

else
ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_PRE_CORRECT[@]}" )
zpwrExpandRegexMatchOnCommandPosition
fi

#dont expand =word because that is zle expand-word
Expand Down Expand Up @@ -325,37 +372,4 @@ function zpwrExpandSupernaturalSpace() {
set +x
fi
}

zpwrExpandTerminateSpace(){

LBUFFER+=" "
}

function zpwrExpandNonFileExpansion(){
:
#DNS lookups
#type -a "$lastWord" &> /dev/null || {
#print -r -- $lastWord | command grep -qE \
#'^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\.?$'\
#&& {
##DNS lookup
#A_Record=$(host $lastWord) 2>/dev/null \
#&& {
#A_Record=$(print -r -- $A_Record | command grep ' address' | head -1 | awk '{print $4}')
#} || A_Record=bad
#[[ $A_Record != bad ]] && \
#LBUFFER="$(print -r -- "$LBUFFER" | sed -E "s@\\b$lastWord@$A_Record@g")"
#} || {
#print -r -- $lastWord | command grep -qE \
#'\b([0-9]{1,3}\.){3}[0-9]{1,3}\b' && {
##reverse DNS lookup
#PTR_Record=$(nslookup $lastWord) 2>/dev/null && {
#PTR_Record=$(print -r -- $PTR_Record | command grep 'name = ' | tail -1 | awk '{print $4}')
#} || PTR_Record=bad
#[[ $PTR_Record != bad ]] && \
#LBUFFER="$(print -r -- "$LBUFFER" | sed -E "s@\\b$lastWord\\b@${PTR_Record:0:-1}@g")"
#}
#}
#}
}
#}}}***********************************************************

0 comments on commit daa988c

Please sign in to comment.