Skip to content

Commit

Permalink
add ZPWR_EXPAND_BLACKLIST
Browse files Browse the repository at this point in the history
  • Loading branch information
MenkeTechnologies committed Dec 10, 2021
1 parent 8d2e303 commit 7e46505
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 19 additions & 18 deletions zpwrExpandLib.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions zsh-expand.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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)$'
Expand Down

0 comments on commit 7e46505

Please sign in to comment.