3

I would like to be able to type a filename in zsh, hit tab, and see a list of files that match that name in any subdirectories of my current directory. Then I could tab through those results and hit enter to select a certain file, just like the built-in zsh tab completion functionality works.

Example desired functionality:

$ emacs app.css [tab] *www/css/app.css* tmp/static/app.css [enter] $ emacs www/css/app.css 

If this is not currently a feature, I assume I could write a custom completion script to implement it.

0

1 Answer 1

3

You can achieve something similar by utilizing the ** pattern (match over multiple directories) and by adding the control function _expand to the completer style (if not already the case).

As a minimum, you need to make the following settings:

autoload -U compinit zstyle ':completion:*' completer _expand compinit 

Then you can get the desired list with

% emacs **/app.css[TAB] 

It even allows for the option to open all matching files at once.

Sign up to request clarification or add additional context in comments.

2 Comments

I really like this solution but when I put it in my .zshrc file it prevents the standard tab complete from working. Where do I need to put this so I can make it work with standard tab complete? I'm using zsh-autosuggestions, I am a software dev but I've not done shell scripting before.
From what I can see, it should not interfere with zsh-autosuggestions. But if compinit is already configured and loaded in your ~/.zshrc, then just adding this as it is might disable some settings. Check, if you already have any of these lines in your configuration, in which case you can just add _expand to the list of arguments after completer. For example, I have zstyle ':completion:*' completer _expand _complete _approximate in my own configuration. If you do not have these lines (especially compinit), you might not be using the "new" (since 2000) completion system.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.