Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sometimes a command doesn't have a completion installed—or syntactically could accept a whole bunch of types of arguments, rendering completion next to useless. For instance, "git checkout" can take the name of any git-tracked file or the name of any ref or other tree-ish. It can also take some option flags. That's a lot of possible completions.

Knowing that I want to complete—say—a branch name, is there a way to bind a key to complete against or display a menu of branch names? (And likewise for any category of completion.)

That seems possible and useful, but I haven't seen it done.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Yes, this can be done. I originally got the following from one of the zsh mailing lists, but I don't recall who posted it:

zle -C complete-file complete-word _generic
zstyle ':completion:complete-file::::' completer _files
bindkey '^x^f' complete-file

This could be easily adapted to use a different completion function rather than _files.

The first line defines a new completion widget named complete-file which behaves like the builtin complete-word widget and uses the _generic function to generate the list of completions.

The second line then configures it so that when that custom widget is used the completer will only use _files to get the list of completions.

Then the third line binds the new widget to a key sequence.

share|improve this answer
    
Win. Thank you! –  Peeja Nov 1 '12 at 19:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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