I'm trying to figure out how to get file completion to work at any word
position on the command line after a set of characters. As listed in a shell these characters would be [ =+-\'\"()]
(the whitespace is tab and space). Zsh will do this, but only after the backtick character, '`', or $(
. mksh does this except not after the characters [+-]
.
By word position on the command line, I'm talking about each set of characters you type out which are delimited by space and a few other characters. For example,
print Hello World
,
has three words
at positions 1-3. At position 1, when you're first typing stuff in, completion is pretty much perfect. File completion works after all of the characters I mentioned. After the first word
, the completion system gets more limited since it's smart. This is useful for commands, but limiting where you can do file completion isn't particularly helpful.
Here are some examples of where file completion doesn't work for me but should in my opinion:
: ${a:=/...}
echo "${a:-/...}"
make LDFLAGS+='-nostdlib /.../crt1.o /.../crti.o ...'
env a=/... b=/... ...
I've looked at rebinding '^I'
(tab) with the handful of different completion widgets Zsh comes with and changing my zstyle ':completion:*'
lines. Nothing has worked so far to change this default Zsh behaviour. I'm thinking I need to create a completion function that I can add to the end of my zstyle ':completion:*' completer ...
line as a last resort completion.
In the completion function, one route would be to cut out the current word
I want to complete, complete it, and then re-insert the completion back into the line if that's possible. It could also be more like _precommand
which shifts the second word
to the first word
so that normal command completion works.
I was able to modify _precommand
so that you can complete commands at any word
position. This is the new file, I named it _commando
and added its directory to my fpath:
#compdef -
# precommands is made local in _main_complete
precommands+=($words[1,$(( CURRENT -1 ))])
shift words
CURRENT=1
_normal
To use it I added it to the end of my ':completion:*' completer ...
line in my zshrc so it works with every program in $path
. Basically whatever word
you're typing in is considered the first word
, so command completion works at every word
position on the command line.
I'm trying to figure out a way to do the same thing for file completion, but it looks a little more complicated at first glace. I'm not really sure where to go with this, so I'm looking to get some help on this.