The problem:
Sometimes, when I try to do things in zsh, it won't complete the filenames I want because they don't apply to the current context. Two examples:
- I want to force-add a file which is currently ignored in hg or git. oh-my-zsh tries to help me by only completing non-ignored files, but in this case it is a hindrance. I'm forced to type the full path to the file manually.
- I want to use
git diff
to diff two arbitrary files on my hard drive. These files do not reside in any repository, but who cares?!git diff --no-index
is a really nice way to diff any two files. But because they aren't in a repo, zsh won't complete them.
The proposed solution:
I could simply edit the source control context to complete all filenames, regardless of their source control status. But there are a couple limitations:
- I don't know how to do that.
- It might be nice to have an "escape hatch" whereby I could force file completion, no matter what the context.
So, I decided instead to bind a key shortcut to force normal, context-free file completion.
What I have so far:
Zsh apparently has an easy way of doing this, as detailed in this question. So I've added the following lines to my .zshrc
:
zle -C complete complete-word complete-files
bindkey '^[[Z' complete
complete-files () { compadd - $PREFIX* }
This causes shift-tab to initiate file completion. It works beautifully in standard zsh! But boo-hoo, for some reason it doesn't work when I source oh-my-zsh. :-(
So is there a way to get this to work with oh-my-zsh, or is there an alternative solution I might find satisfying?