From b6f67134551faaf35a8edc766364879c9dad50b7 Mon Sep 17 00:00:00 2001 From: MenkeTechnologies Date: Fri, 10 Dec 2021 16:56:56 -0500 Subject: [PATCH] remove indirect ref antipattern due to lack of nested arrays in zsh --- README.md | 6 +++--- zpwrExpandApi.zsh | 12 +++++------- zpwrExpandLib.zsh | 12 ++++++------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index b3d1e00..0df5db7 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Expansion on history, globs, parameters and mispellings occurs when cursor is on There is optional expansion of unexpanded line into history on accepting current line with enter key. Expansion occurs for aliases not spelling correction. Globs and other expansions can be optionally enabled on accepting line. See [below](#optional-expansion-of-unexpanded-line-into-history-on-enter). ## Demo -[![asciicast](https://asciinema.org/a/wRe4hwlGNdEbeHk7gZ25sRq5U.svg)](https://asciinema.org/a/wRe4hwlGNdEbeHk7gZ25sRq5U) +[![asciicast](https://asciinema.org/a/FbFsuMCSLtooqkB5ZZbBZeiEg.svg)](https://asciinema.org/a/FbFsuMCSLtooqkB5ZZbBZeiEg) ## Comparison to other expanding abbrevation libraries ### [zsh-abbr](https://github.com/olets/zsh-abbr) @@ -37,9 +37,9 @@ There is optional expansion of unexpanded line into history on accepting current - zsh-expand expands incorrect spellings and phrases, globs, command/process substitution, =command expansion, history expansion and $parameters ## Bypassing expansion -Expansion can be temporarily bypassed with control-space. The variable `ZPWR_EXPAND_BLACKLIST` which should be an array of blacklisted items will blacklist items permanently. +Expansion can be temporarily bypassed with control-space. The variable `ZPWR_EXPAND_BLACKLIST` can be set to an array of regular or global aliases which will not be expanded. -You can override the following environment variables to control expansion. +You can override the following variables to control expansion. ```sh # ignore expansion of these regular/global aliases export ZPWR_EXPAND_BLACKLIST=(g gco) diff --git a/zpwrExpandApi.zsh b/zpwrExpandApi.zsh index 7e57c4b..d9593db 100644 --- a/zpwrExpandApi.zsh +++ b/zpwrExpandApi.zsh @@ -63,11 +63,9 @@ function zpwrExpandParseWords(){ ZPWR_EXPAND_WORDS_LPARTITION=( $mywordsleft[$firstIndex,$#mywordsleft] ) - ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]=ZPWR_EXPAND_WORDS_LPARTITION + #zpwrLogDebug "lpartition = '$ZPWR_EXPAND_WORDS_LPARTITION'" - #zpwrLogDebug "lpartition = '${(P)ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]}'" - - lpartAry=( ${(z)${(P)ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]}} ) + lpartAry=( ${(z)${ZPWR_EXPAND_WORDS_LPARTITION}} ) ZPWR_VARS[firstword_partition]=${lpartAry[1]} @@ -98,7 +96,7 @@ function zpwrExpandLastWordAtCommandPosAndExpand(){ local caller=$2 local triggerKey=$3 - if (( ${(P)#ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]} == 1 )); then + if (( $#ZPWR_EXPAND_WORDS_LPARTITION == 1 )); then if [[ $caller == zle ]]; then zpwrExpandGetAliasValue words=(${(z)ZPWR_VARS[EXPANDED]}) @@ -118,7 +116,7 @@ function zpwrExpandLastWordAtCommandPosAndExpand(){ ZPWR_VARS[LAST_WORD_WAS_AT_COMMAND]=true ZPWR_VARS[ORIGINAL_LAST_COMMAND]=$ZPWR_VARS[lastword_lbuffer] - elif (( ${(P)#ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]} >= 2 )); then + elif (( $#ZPWR_EXPAND_WORDS_LPARTITION >= 2 )); then # regular alias expansion after sudo if [[ $ZPWR_EXPAND_SECOND_POSITION == true ]]; then @@ -144,7 +142,7 @@ function zpwrExpandLastWordAtCommandPosAndExpand(){ fi else # here if not called by supernatural space fn - if [[ "${(P)ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]}" =~ "$ZPWR_VARS[continueFirstPositionRegex]" ]];then + if [[ "$ZPWR_EXPAND_WORDS_LPARTITION" =~ "$ZPWR_VARS[continueFirstPositionRegex]" ]];then ZPWR_EXPAND_PRE_EXPAND=("${(z)match[-1]}") if (( $#ZPWR_EXPAND_PRE_EXPAND == 1)); then diff --git a/zpwrExpandLib.zsh b/zpwrExpandLib.zsh index 4d5d006..72b2d7f 100755 --- a/zpwrExpandLib.zsh +++ b/zpwrExpandLib.zsh @@ -54,7 +54,7 @@ function zpwrExpandCorrectWord(){ return fi - if (( ${(P)#ZPWR_VARS[ZPWR_EXPAND_WORDS_PARTITION]} == 1)); then + if (( $#ZPWR_EXPAND_WORDS_PARTITION == 1)); then if type -a $ZPWR_VARS[firstword_partition] &>/dev/null; then #zpwrLogDebug "No correction from 1 word => '"'$ZPWR_VARS[firstword_partition]'"'_____ = ""'$ZPWR_VARS[firstword_partition]'" # git @@ -62,7 +62,7 @@ function zpwrExpandCorrectWord(){ fi else - if [[ "${(P)ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]}" =~ "$ZPWR_VARS[continueFirstPositionRegexNoZpwr]" ]];then + if [[ "$ZPWR_EXPAND_WORDS_LPARTITION" =~ "$ZPWR_VARS[continueFirstPositionRegexNoZpwr]" ]];then ZPWR_EXPAND_PRE_CORRECT=("${(z)match[-1]}") #zpwrLogDebug "${match[@]}" @@ -84,7 +84,7 @@ function zpwrExpandCorrectWord(){ fi else - #zpwrLogDebug "no match ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION] '$ZPWR_VARS[ZPWR_EXPAND_WORDS_LPARTITION]'" + #zpwrLogDebug "no match ZPWR_EXPAND_WORDS_LPARTITION '$ZPWR_EXPAND_WORDS_LPARTITION'" zpwrLogConsoleErr zpwr expand should not reach here return fi @@ -245,13 +245,13 @@ function zpwrExpandSupernaturalSpace() { if [[ $ZPWR_VARS[foundIncorrect] = true && $ZPWR_CORRECT_EXPAND = true ]]; then #zpwrLogDebug "RE-EXPAND after incorrect spelling" - ZPWR_EXPAND_PRE_EXPAND=("${ZPWR_EXPAND_POST_CORRECT[@]}") + ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_POST_CORRECT[@]}" ) zpwrExpandParseWords "$LBUFFER" else - ZPWR_EXPAND_PRE_EXPAND=("${ZPWR_EXPAND_PRE_CORRECT[@]}") + ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_PRE_CORRECT[@]}" ) fi else - ZPWR_EXPAND_PRE_EXPAND=("${ZPWR_EXPAND_PRE_CORRECT[@]}") + ZPWR_EXPAND_PRE_EXPAND=( "${ZPWR_EXPAND_PRE_CORRECT[@]}" ) fi #dont expand =word because that is zle expand-word