在Linux上放置zsh自动完成脚本的位置在哪里?

20
安装了cheat(命令行中的命令速查表)之后,我尝试使用提供的zsh脚本启用自动补全。然而,我似乎找不到脚本的正确位置。

目前为止

  • 获取cheat.zsh
  • 将其复制到~/.oh-my-zsh/custom/plugins/cheat/_cheat.zsh
  • cheat添加到plugins数组中的~/.zshrc中;
  • 重新加载shell。

在键入cheat d<TAB>时,自动补全没有发生。

问题

那么,在Linux上应该将zsh自动补全脚本放在哪里?


尝试将其添加到~/.bash_profile中。像这样:'source .oh-my-zsh/custom/plugins/cheat/_cheat.zsh' - Maximin
4
他正在使用 Zsh 而不是 Bash。 - tripleee
2个回答

23

我在$FPATH中没有~/.oh-my-zsh/custom/plugins/cheat/,但我有另一个自定义插件。所以我猜我的source $HOME/.zshrc不够用。 - Édouard Lopez

13

让我来帮忙。

我曾尝试过类似的事情,这是我如何使其工作的。 以下解决方案已在debian发行版[ubuntu]上使用oh-my-zsh验证过。

问题

  > 您的zsh未能提供正确的完成建议,例如[conda]
  > 当您键入#conda tab时,会得到以下结果

enter image description here

解决方案

  1. Find the completion script

    one great location is https://github.com/clarketm/zsh-completions/tree/master/src

  2. Download the file to completions folder [~/.oh-my-zsh/completions]

    wget https://raw.githubusercontent.com/clarketm/zsh-completions/master/src/_conda ~/.oh-my-zsh/completions
    
  3. Make sure the completions folder is listed under $fpath

    print -l $fpath
    
    1. What if its not listed It should have normaly added with .oh-my-zsh.sh If not append below to ~/.oh-my-zsh/oh-my-zsh.sh

      # add a function path
      fpath=($ZSH/functions $ZSH/completions $fpath)
      
    2. source .zshrc

      source ~/.zshrc
      
  4. Execute compinit this will build ~/.zcompdump file for the functions

    compinit
    

enter image description here

Troubleshooting

  1. Due to conflicts the suggestions might not be shown try the following

    rm -f ~/.zcompdump; compinit
    # we are clearing the function dump stored by zsh, its safe zsh will rebuilt it.
    
  2. Try source .zshrc

    source ~/.zshrc
    
  3. Try loggin out and login

  4. Check the mapping in ~/.zcompdump

    vi ~/.zcompdump
    

    search for conda

    [/conda]

    you should see as below

    'conda' '_conda'

希望有人会发现这篇文章有用,如果确实有用的话,我很乐意提供帮助。


我正在添加一个完成脚本,发现文件名中有一个连字符/破折号,它没有加载到~/.zcompdump中。当我将其重命名为下划线时,它就正常工作了。请在其中提到这一点。另外,还有一点需要提到,如果有人没有提供zsh完成脚本,他们可以按照这些步骤进行操作:https://unix.stackexchange.com/a/535646/140177 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接