3

I usually put a date before a file or directory name similar to 2014-04-20 file_name.doc.

So, in a folder there is usually a bunch of files and directories starting with a date.

But when accessing these folders from command line, bash in my case, it is a little annoying, because I have to type all the dates and only after that hit the TAB for autocomplete.

What I want is to type only some part of the file name and after hitting TAB the system should put the full name on prompt.

Is there any solution for this?

  • zsh supports this behaviour. – muru Dec 9 '14 at 8:12
  • 1
    fish also support it. – jherran Dec 9 '14 at 8:16
  • 2
    I tried fish -- excellent! – B.I. Dec 9 '14 at 14:01
1

Complete a wildcard pattern:

ls *file_n*Tab

If the pattern matches multiple files, you'll be prompted for choices or the list will be interpolated into the command line, depending on your completion options. If you want to cancel that and type a few more characters to restrict the matches, undo the completion (Ctrl+_).

If you use context-sensitive completion, Tab doesn't expand wildcards by default (there may be an option you can set to rectify that), but Ctrl+X *.

0

You can use complete to do what you want (existing completion script are located in /etc/bash_completion.d under debian, after installing the appropriate package)

You can check the apache2.2-common to have a basic example.

https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html

0

If you use \eg (glob-complete-word), you don't need to type the second asterisk, or you can for example type *file_n\eg instead of *file_n*<tab>.

If there are multiple files that match the pattern, you can insert the first match with menu-complete or the last match with menu-complete-backward. If you for example add

"\et": menu-complete
"\er": menu-complete-backward

to ~/.inputrc, *file_n*\et completes to the first match and *file_n*\er completes to the last match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.