3

I have a simple issue with zsh. Sometimes, I am in a directory with multiples sub-directories.

So, when I do a $ ls[TAB] or $cd[TAB], I list all these sub-directories.

But how to accept one of the suggestions for sub-directories? Is there a short cut or a key to choose a directory to go deeper in this directory.

I must precise that I don't know systematically the content of these subdirectories, so I can't often choose a subdirectory in which the first letter of filename could allow me to choose automatically the sub-directory to explore.

I was looking for a solution on the web but documentation about zsh completion is pretty big.

halfer
  • 19,824
  • 17
  • 99
  • 186

2 Answers2

0

The only way I know is: double click your target + cmd c + cmd v and then press Enter.

Dan M
  • 4,340
  • 8
  • 20
  • Thanks for your answer. Unfortunately, I am looking for a short cut or a key to apply to choose one particular directory among the completion list done by [TAB] key. –  May 30 '20 at 15:50
0

Edit: simplest solution to accomplish the desired effect: press [/] key to 'accept' the current suggested directory ; then press again [tab] key to show suggestions of its subdirectories

Old suggested solution:

Install https://ohmyz.sh/

Then pressing the [tab] key displays a list and the first item is highlighted. Hit the [tab] key again to choose the desired item and hit the [enter] key to write it in the command line interface, without actually executing the command, only as if you have just typed it in.

Then you can continue hitting the [tab] key to select another subdirectory, and so on.

It also works on any autocompletable, not only dirs.

Wen Zul
  • 66
  • 5
  • I would be fine to know how to `ohmyzsh' is implemented to allow this functionnality of "choosing a directory to go deeper", have you got an idea ? –  Jun 05 '20 at 07:56
  • It is possible to see all the source code, it is in github (https://github.com/ohmyzsh/ohmyzsh/) but there is a lot of functionality, you may have to dig deep ;-). But spend time to extract only that functionality may not worth the effort, also you where missing a lot of other usefull stuff. – Wen Zul Jun 05 '20 at 13:14
  • Said that, I think you best option is just use the key [/] (slash) to accept the suggested directory completion, and press again [tab] to see deeper subdirectories. It has to be an option in zsh to change the behavior of pressing [enter] in this context, but I cannot find it. This is the page of the options for .zshrc: http://zsh.sourceforge.net/Doc/Release/Options.html – Wen Zul Jun 05 '20 at 13:19
  • will edit the answer to to add the accepted suggestion – Wen Zul Jun 06 '20 at 15:40