Where to place zsh autocompletion script on Linux?

12,382

Solution 1

I got this to work by adding cheat.zsh to the ~/.oh-my-zsh/plugins directory. Zsh checks to autoload functions on FPATH, so try:

echo $FPATH

and then either add to FPATH or move the file into a folder on the path.

This actually does a much better job of explaining it: https://unix.stackexchange.com/questions/33255/how-to-define-and-load-your-own-shell-function-in-zsh

Solution 2

Let me try to help here.

I was trying something similar and this is how I was able to get it worked. Below solution has verified with oh-my-zsh on debian distro [ubuntu]

Problem

  > Your zsh isnt giving proper completion suggestions say [conda]
  > This is what you get when you type in # conda tab

enter image description here

Solution

  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'

Hope someone will find it useful, if so Happy to Help

Share:
12,382

Related videos on Youtube

Édouard Lopez
Author by

Édouard Lopez

Motivation I'm a quality-driven full-stack developer loving UX and devOps. Workflow include TDD and tests ; pair-programming ; code-review ; Trunk-based development ; Agile related. Languages and Tools Frontend: JS, ES6+, ReactJS, Vue.js, EmberJS, Angular, webpack/rollup ; test: unit Jest, AVA, end-to-end Cypress Backend: Python, Flask, Django, Unittest and Pytest ; DevOps: Docker/compose/Docker.py, Ansible ; Shell: bash/sh, fish, powershell test: Bats, fishtape, Pester Bonus I'm familiar with: UX (User eXperience) ; Accessibility ; Data-visualization ; IA (Information Architecture).

Updated on June 07, 2022

Comments

  • Édouard Lopez
    Édouard Lopez almost 2 years

    After installing cheat (command cheat sheets from the command line), I tried to enable the autocompletion using the provided zsh script. However, I don't seem to find the correct location for the script.

    So far

    • I fetch the cheat.zsh ;
    • copy it to ~/.oh-my-zsh/custom/plugins/cheat/_cheat.zsh ;
    • add the cheat to the plugins array in my ~/.zshrc ;
    • reload my shell.

    Auto-completion doesn't happen when typing cheat d<TAB>.

    Question

    So where to place zsh auto-completion script on Linux?

    • tripleee
      tripleee over 9 years
      @Maximin: He is using Zsh, not Bash.
  • Édouard Lopez
    Édouard Lopez over 9 years
    I don't got ~/.oh-my-zsh/custom/plugins/cheat/ in the $FPATH however I got another cutsom plugin. So I guess my source $HOME/.zshrc isn't enough.