diff --git a/README.md b/README.md index f04d024..404a0fa 100644 --- a/README.md +++ b/README.md @@ -37,10 +37,12 @@ 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. +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. You can override the following environment variables to control expansion. ```sh +# ignore expansion of these regular/global aliases +export ZPWR_EXPAND_BLACKLIST=(g gco) # aliases expand in first position export ZPWR_EXPAND=true # aliases expand in second position after sudo diff --git a/zpwrExpandLib.zsh b/zpwrExpandLib.zsh index b1e5a9b..283a8fd 100755 --- a/zpwrExpandLib.zsh +++ b/zpwrExpandLib.zsh @@ -256,29 +256,30 @@ function zpwrExpandSupernaturalSpace() { #dont expand =word because that is zle expand-word if [[ ${ZPWR_VARS[lastword_lbuffer]:0:1} != '=' ]] && (( $#ZPWR_VARS[lastword_lbuffer] > 0 ));then - if (( ${+aliases[${ZPWR_VARS[lastword_lbuffer]}]} )) && ! [[ ${aliases[${ZPWR_VARS[lastword_lbuffer]}]} =~ $ZPWR_VARS[blacklistFirstPosRegex] ]];then - - #zpwrLogDebug "regular=>'$ZPWR_VARS[lastword_lbuffer]'" - zpwrExpandRightTrim - zpwrExpandLastWordAtCommandPosAndExpand moveCursor zle "$triggerKey" - else - #zpwrLogDebug "NOT regular=>'$ZPWR_VARS[lastword_lbuffer]'" - if (( ${+galiases[${ZPWR_VARS[lastword_lbuffer]}]} )); then + if [[ -z $ZPWR_VARS[userBlacklist] ]] || ! [[ $ZPWR_VARS[lastword_lbuffer] =~ $ZPWR_VARS[userBlacklist] ]]; then + if (( ${+aliases[${ZPWR_VARS[lastword_lbuffer]}]} )) && ! [[ ${aliases[${ZPWR_VARS[lastword_lbuffer]}]} =~ $ZPWR_VARS[blacklistFirstPosRegex] ]];then + #zpwrLogDebug "regular=>'$ZPWR_VARS[lastword_lbuffer]'" zpwrExpandRightTrim - # global alias expansion - #zpwrLogDebug "global=>'$ZPWR_VARS[lastword_lbuffer]'" - zpwrExpandGlobalAliases "$ZPWR_VARS[lastword_lbuffer]" - ZPWR_VARS[LAST_WORD_WAS_AT_COMMAND]=true - ZPWR_VARS[ORIGINAL_LAST_COMMAND]=$ZPWR_VARS[lastword_lbuffer] + zpwrExpandLastWordAtCommandPosAndExpand moveCursor zle "$triggerKey" + else + #zpwrLogDebug "NOT regular=>'$ZPWR_VARS[lastword_lbuffer]'" + if (( ${+galiases[${ZPWR_VARS[lastword_lbuffer]}]} )); then + + zpwrExpandRightTrim + # global alias expansion + #zpwrLogDebug "global=>'$ZPWR_VARS[lastword_lbuffer]'" + zpwrExpandGlobalAliases "$ZPWR_VARS[lastword_lbuffer]" + ZPWR_VARS[LAST_WORD_WAS_AT_COMMAND]=true + ZPWR_VARS[ORIGINAL_LAST_COMMAND]=$ZPWR_VARS[lastword_lbuffer] + fi + fi + if [[ ! -f "$ZPWR_VARS[lastword_lbuffer]" ]]; then + zpwrExpandNonFileExpansion fi fi - if [[ ! -f "$ZPWR_VARS[lastword_lbuffer]" ]]; then - zpwrExpandNonFileExpansion - else - : - fi fi + if [[ $ZPWR_VARS[LAST_WORD_WAS_AT_COMMAND] != true ]]; then # expand file globs, history expansions, command expansion, parameter expansion and =command if [[ $ZPWR_EXPAND_NATIVE == true ]]; then diff --git a/zsh-expand.plugin.zsh b/zsh-expand.plugin.zsh index 9471d88..1883f97 100644 --- a/zsh-expand.plugin.zsh +++ b/zsh-expand.plugin.zsh @@ -46,6 +46,11 @@ fi ZPWR_VARS[builtinSkips]='(command|time|exec|eval|nocorrect|noglob)' +ZPWR_VARS[userBlacklist]="" +if (( $#ZPWR_EXPAND_BLACKLIST)); then + ZPWR_VARS[userBlacklist]="^(${(j:|:)ZPWR_EXPAND_BLACKLIST})$" +fi + ZPWR_VARS[blacklistFirstPosRegex]='^(omz_history|grc|_z|zshz|cd|hub|_zsh_tmux_|_rails_|_rake_|mvn-or|gradle-or|noglob |rlwrap ).*$' ZPWR_VARS[blackSubcommandPositionRegex]='^(cargo|jenv|svn|git|ng|pod|docker|kubectl|rndc|yarn|npm|pip[0-9\.]*|bundle|rails|gem|nmcli|brew|apt|dnf|yum|zypper|pacman|service|proxychains[0-9\.]*|zpwr|zm|zd|zg|zinit)$'