wting / autojump

A cd command that learns - easily navigate directories from the command line
Other
16.2k stars 706 forks source link

Autocomplete in zsh (with oh-my-zsh) not working #353

Open nunoh opened 9 years ago

nunoh commented 9 years ago

Sorry, if I am missing something obvious, but hopefully you might be able to tell me what that is.

I have installed autojump with brew in my setup of zsh (version 5.0.7) and oh-my-zsh but don't seem to be able to use tab autocompletion, instead I am just getting the files and folders of the current dir.

I've added the [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh line to my .zshrc and also tried enabling the autojump plugin that comes with oh-my-zsh (should I?). In any case, I wasn't able to get the tab completion working. Everything else works ok.

What am I missing? Thanks!

jutkko commented 9 years ago

For me as well. TABbing in autojump is not doing anything...

politicus commented 9 years ago

Tabbing in autojump is stil not doing anything.

cloudyan commented 9 years ago

+1,I am just getting the files and folders of the current dir too. why ??? I installed autojump with brew ,but it's not working

cloudyan commented 9 years ago

In mac, it's not working; but in ubuntu it's OK

anrao91 commented 8 years ago

My fix for this issue is - 1) Execute the zshrc in the bash first, and then change the SHELL, say - $~/.zshrc $ZSH

Provided you have followed the installation steps given here - https://github.com/robbyrussell/oh-my-zsh/blob/master/README.markdown

P.S : It worked in mac for me

chenglou commented 8 years ago

FWIW, I'm on Mac too (with zsh). Had this problem a while ago, but it's been fixed for a while for me.

kud commented 5 years ago

I've got the same problem:

image
boyoungzheng commented 4 years ago

Same here. Any updates?

boyoungzheng commented 4 years ago

With oh-my-zsh, the autojump completion works. Without oh-my-zsh, the completion does not work.

I installed autojump through homebrew. I made sure [ -f /usr/local/etc/profile.d/autojump.sh ] && . /usr/local/etc/profile.d/autojump.sh is in my ~/.zshrc

autojump v22.5.3 zsh 5.7.1 (x86_64-apple-darwin19.0)

boyoungzheng commented 4 years ago

I think I've found the solution while reading Moving to zsh Without on-my-zsh, I need to run autoload -Uz compinit && compinit I also found a similar command in ~/.oh-my-zsh/oh-my-zsh.sh autoload -U compaudit compinit I guess the key thing is the compinit.

(If my solution also works for you, please give me a thumb up. 😃)

victor-h-b commented 4 years ago

@boyoungzheng your solution worked for me, except it's adding annoying double underscore ("__") after the typed text:

so: $ j tmp<tab><tab>

turns into:

$ j tmp__

tmp__1__/bla/tmp-something
tmp__2__/bla/another-tmp
...

there are also few identical suggestions, which seem like a bug. but good enough for me :)

MauritsDescamps commented 4 years ago

@boyoungzheng your solution worked for me, except it's adding annoying double underscore ("__") after the typed text:

so: $ j tmp<tab><tab>

turns into:

$ j tmp__

tmp__1__/bla/tmp-something
tmp__2__/bla/another-tmp
...

there are also few identical suggestions, which seem like a bug. but good enough for me :)

Did you manage to fix this? I'm having the same problem. Autocomplete works but it just shows two underscores.

victor-h-b commented 4 years ago

@MauritsDescamps no, I haven't managed to solve it.

shaungrady commented 3 years ago

Anyone find a fix for this yet? I'm stuck with Maurits' issue also.

shaungrady commented 3 years ago

Well apparently it's it's a feature:

ZSH tab completion fixed.

ZSH behavior now matches Bash behavior. However it requires the compinit module to be loaded. Add the following line to ~/.zshrc:

autoload -U compinit; compinit

To use type:

j

A menu showing the top database entries will be displayed. Type in any number followed by to complete the entry.

rkulla commented 3 years ago

@shaungrady Interesting. Ok I ran that and got some initial warnings about insecure directories. That was easy to resolve by running compaudit and fixing the permissions those the directories listed.

The markup in that file isn't right so I had to read the RAW form of the README to see what it was saying. It said to type j followed by space followed by 2 tabs and the enter the number you want to jump to but that just pops up two underscores for me. However, I can do j xTABTAB to expand to x__1_foo x__2_bar and enter 2 to jump to bar.

If this is the best it functions that's fine, but something still seems a little off to me. Thanks.

mesaglio commented 3 years ago

Hi, i add de plugin autojump un .zshrc file, and works. MacOS Catalina V10.15.7 autojump v22.5.3

plugins=(git autojump)

mesaglio commented 3 years ago

Hi, i add de plugin autojump un .zshrc file, and works. MacOS Catalina V10.15.7 autojump v22.5.3

plugins=(git autojump)

And move the source $ZSH/oh-my-zsh.sh line from .zshrc at the end of the same file.

rkulla commented 3 years ago

I really think @shaungrady has solved this issue by saying to add autoload -U compinit; compinit to get completion to work. (man zshcontrib). The plugins=(autojump) thing is only necessary if you use oh-my-zsh but that plugin is just a script (autojump.plugin.zsh) that sources the autojump profile script.

If you don't use oh-my-zsh, like I don't, you still have to source the script (which will be in a different location depending on what OS and/or how you installed it, e.g., for me on MacOS installing autojump with Homebrew, it's in /usr/local/etc/profile.d/autojump.sh).

In summary, the steps whether you use oh-my-zsh or regular zsh are: 1) In .zshrc, source the autojump profile script (or if using oh-my-zsh just have plugins=(autojump) source it for you. 2) In .zshrc, make completion work by adding autoload -U compinit; compinit -y 3) Start completing things by typing j foo[tab][tab] and when the menu pops up, enter the directory number and enter.

jeremyfix commented 3 years ago

@rkulla I did experience the same issue on Ubuntu 18.04, oh-my-zsh .

I did add the autoload -U compinit; compinit -y in my zshrc as suggested and I got the tab completion working now ! Thank you !

emacdona commented 3 years ago

I'm not going to pretend to know anything about compinit, but some experimentation has shown that running it clobbers any auto completion that has already been configured. This coupled with tons of recommendations on the web to run it to "fix" autocompletion issues appears to have led to multiple projects including it in their auto completion initialization files (two that I use: nvm and sdkman appear to have done so) -- which results in the latest one to load clobbering the configuration of all those before it!

So, here's what I put in my .zshrc to "fix" it. Seems to be working well enough so far... not sure what issue I may run into in the future:

autoload -Uz compinit
compinit -u

# It seems that countless recommendations on the web to run:
# autoload -Uz compinit && compinit

# Have resulted in everyone's zsh autocomplete initialization running that. I have no idea
# what it does, however experimentation has shown that running "compinit" clobbers any
# completions you already had configured. Which totally sucks if you configure auto completion
# for multiple tools in your zshrc
alias compinit="echo no more compinit!"
adrienafl commented 2 years ago

Fixed it by adding this to .zshrc (Apple M1)

  if type brew &>/dev/null; then
      FPATH=$(brew --prefix)/share/zsh-completions:$(brew --prefix)/share/zsh/site-functions:$FPATH

    autoload -Uz compinit
    compinit
  fi
shaohuahuang commented 2 years ago

@shaungrady MauritsDescamps Is the two underscore issue resolved? I encounter the same issuerecently

I tried to add below line into my .zshrc file, it does not resolve the issue. autoload -U compinit; compinit

shaungrady commented 2 years ago

@shaohuahuang It's a feature:

Example:

$ j tmp__

tmp__1__/bla/tmp-something
tmp__2__/bla/another-tmp

You press 1 to jump to the first option, or 2 to jump to the second option.

cloudyan commented 2 years ago

In mac, it's not working; but in ubuntu it's OK

I now use z instead of autojump

image

Hanlen commented 1 year ago

make sure that your code source xxx/xxx/autojump.sh is before the code source $ZSH/oh-my-zsh.sh