哦-my-zsh别名不自动完成

时间:2014-06-04 18:36:34

标签: plugins autocomplete alias zsh zshrc

我对自己的智慧有点研究......我只需要问。

我在小牛机器上有哦-my-zsh并且更新了所有内容。我也有Xcode和Brew。全部更新。根据这个页面:https://github.com/robbyrussell/oh-my-zsh/wiki/Cheatsheet我不应该只是打字,说:" g" [tab]并获得" git"?或键入" md" [tab]并获得" mkdir -p"?现在我只是得到一个我可以通过选项卡(或箭头)的选项列表......我认为它会自动完成。我错过了什么?

我觉得这可能与我的$ PATH有关,但这也是我感到困惑的地方......应该指向哪里?

我非常欣赏和启发。

# Path to your oh-my-zsh configuration.
#ZSH=$HOME/.oh-my-zsh
 export ZSH=$HOME/.oh-my-zsh

# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
#ZSH_THEME="af-magic"
 ZSH_THEME="agnoster"

# Set to this to use case-sensitive completion
# CASE_SENSITIVE="true"

# Comment this out to disable weekly auto-update checks
# DISABLE_AUTO_UPDATE="true"

# Uncomment following line if you want to disable colors in ls
# DISABLE_LS_COLORS="true"

# Uncomment following line if you want to disable autosetting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment following line if you want red dots to be displayed while waiting for completion
 COMPLETION_WAITING_DOTS="true"

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Example format: plugins=(rails git textmate ruby lighthouse)
 plugins=(git textmate sublime zsh-syntax-highlighting)

 source $ZSH/oh-my-zsh.sh

#export PATH=/usr/local/bin:/usr/local/sbin:/usr/local/git/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/X11/$
#export PATH=$HOME/bin:/usr/local/bin:$PATH
 export PATH=/usr/local/bin:$PATH

[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"

 zstyle ':completion:*' list-prompt   ''
 zstyle ':completion:*' select-prompt ''

 autoload -Uz compinit
 compinit

1 个答案:

答案 0 :(得分:1)

别名基本上只是命令的短名称。在执行命令之前,zsh在内部用其值替换别名。但默认情况下,使用完成时不会扩展别名( Tab ),它们的处理方式与其他任何命令一样。

例如:

alias ll='ls -l'
alias la='ls -al'

如果您现在键入l Tab ,zsh会显示以l开头的每个命令,包括别名llla 。如果您键入ll Tab ,它可能只会在ll之后添加一个空格(假设没有其他命令以ll开头)。

当您运行ll somedir时,它与ls -l somedir完全相同。您甚至可以添加ls的其他选项:ll -t somedir运行ls -l -t somedir


话虽如此,如果您想在键入 Tab 时扩展别名,zsh可以这样做。

有两种方法:

  1. 您可以调用_expand_alias小部件。在 emacs模式(bindkey -e)中,它绑定到^Xa(按 Control + X 然后 A )。

  2. 您可以将_expand_alias添加到completer样式。似乎 oh-my-zsh 不会将此样式更改为其默认值,因此添加

    zstyle ':completion:*' completer _expand_alias _complete _ignored

    ~/.zshrc应该有效。

    (要保存,您可以使用zstyle -L ':completion:*' completer打印当前设置,_expand_alias必须在_complete之前

    如果您现在输入ll 标签zsh会立即将其替换为ls -l

  3. 注意:在这两种情况下,光标必须位于替换发生的别名之后或之后。这也意味着如果自动完成,您必须键入整个别名或退格(_completer成功完成后添加空格)

相关问题