Zsh alias extension

Is it possible to configure zsh to expand global aliases during tab completion? For example, I have common aliases:

alias -g '...'='../..'
alias -g '....'='../../..'

but when I type, for example cd .../some<tab>, it will not expand to cd .../somethingor cd ../../something. Therefore, I often will not use these convenient aliases, because they are incompatible with tab completion.

+5
source share
2 answers

I am a user of Michael Magnusson rationalise-dot. From my zshrc:

# This was written entirely by Mikael Magnusson (Mikachu)
# Basically type '...' to get '../..' with successive . adding /..
function rationalise-dot {
    local MATCH # keep the regex match from leaking to the environment
    if [[ $LBUFFER =~ '(^|/| |      |'$'\n''|\||;|&)\.\.$' ]]; then
      LBUFFER+=/
      zle self-insert
      zle self-insert
    else
      zle self-insert
    fi
}
zle -N rationalise-dot
bindkey . rationalise-dot
# without this, typing a . aborts incremental history search
bindkey -M isearch . self-insert
+10
source

zsh. "", , , . , , ...<SPACE> ../...

, , :

typeset -A abbrevs
abbrevs=(
        "..." "../.."
        "...." "../../.."        
)

#create aliases for the abbrevs too
for abbr in ${(k)abbrevs}; do
   alias -g $abbr="${abbrevs[$abbr]}"
done

my-expand-abbrev() {
    local MATCH
    LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
    LBUFFER+=${abbrevs[$MATCH]:-$MATCH}
    zle self-insert
}

bindkey " " my-expand-abbrev 
+5

All Articles