Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing zsh auto complete

I decided to give zsh a try. First i'll describe how things work right now and then i'll describe how I would like them to work.

Lets say I have 2 subfolders in current folder, 1st one "Documents", 2nd one "Downloads".

  1. If I type "cd D" and press TAB, it will auto complete with "Do".

  2. Press TAB again, it will auto complete with "Documents".

  3. Press TAB again, it will auto complete with "Downloads".

  4. Press TAB again, it will auto complete with "Documents" (I appreciate that here it dosen't go back to "Do" like Bash does).

  5. At this point I have to pres Enter twice to change the directory. (first Enter to select "Documents" and second one to execute the comand).

How I would like zsh to behave:

  1. If I type "cd D" and press TAB, I would like to auto complete with "Documents".
  2. Press TAB again, should auto complete with "Downloads".
  3. Press TAB again, should auto complete with "Documents".
  4. Press Enter once and the directory should change to "Documents".

How can I do this? :-)

like image 864
user3388129 Avatar asked Mar 06 '14 12:03

user3388129


1 Answers

Wow, one year and no replies. I hope you found out how, but for others who might come across this via a search...

First make sure you have the completion module loaded with this line

zmodload zsh/complist

Then you can bind Enter, aka ^M, during menuselect to the function accept-line - which is normal behaviour - but by prefixing it with a dot, if forces it to leave menuselect mode before the function executes

bindkey -M menuselect '^M' .accept-line
like image 95
Joshua Avatar answered Oct 13 '22 13:10

Joshua