I use Zsh predominantly, one of the features I really enjoy is path/filename completion.

The specific behavior I'm most interested in:

  1. Completing a full filepath from partial matches, e.g.

    ~/w/m/src  (TAB)


  2. Completion to a name at depth e.g.

    ~///src (TAB)

    Completion candidates are all matches of src three folders deep from home.

How can I configure Bash to complete filepath names like this?

(Btw: I know about autojump, this question is specifically for Bash completion configuration.)

  • You cannot, at least not easily. You would need to write a function that splits the path given so far into its component directories, find a suitable expansion for each in order, then put the pieces back together into a single suggestion. – chepner Mar 8 '17 at 21:55
  • Which, presumably, is what the zsh folks have already done. I'd love to find a way to do this in bash but given that there is already an excellent (and mostly sh-compatible) shell that does this already, I doubt you'll find an easy solution short of writing it yourself. – terdon Mar 8 '17 at 21:59
  • I had a feeling I would need to do this myself, but it might be fun. Or I'll make do with fzf or autojump – ocodo Mar 9 '17 at 4:23

Your Answer

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

Browse other questions tagged or ask your own question.