zsh别名扩展

时间:2011-01-19 17:42:16

标签: zsh zshrc

是否可以在标签完成期间配置zsh以扩展全局别名?例如,我有常见的别名:

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

但是当我输入cd .../some<tab>时,它不会扩展为cd .../somethingcd ../../something。因此,我经常不会使用这些方便的别名,因为它们与制表符完成不兼容。

2 个答案:

答案 0 :(得分:10)

我是Mikael Magnusson rationalise-dot的用户。来自我的zshrc:

# This was written entirely by Mikael Magnusson (Mikachu)
# Basically type '...' to get '../..' with successive .'s 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

答案 1 :(得分:5)