Edit: OK. Seems like I might have misread the situation. Thought you meant program options as in:
$ mplayer_alias -pla<tab><tab>
-playing-msg -playlist
$
but guess it is file completion. I don't know, but give it a go.
As a quick fix this should work:
complete -f -o default ee
Giving:
$ ee<tab><tab>
file1 file2 file3
$
as of Programmable Completion Builtins. E.g. the -X pattern
can be useful. E.g. to exclude .swp
and .swo
files:
complete -f -X '*.sw[op]' ee
only show .zip
, .ZIP
:
complete -f -o default -X '!*.+(zip|ZIP)' my_unzip_alias
some might need you to add shopt -s extglob
in configuration file.
OLD Answer:
You could try out something like this in your .bash_completion
.
At least as a starter.
The core idea is to simply add complete
for the alias using the existing
complete script for the real program. Here I assume that they are all in the format:
complete -F _complete_function_from_original program_name
You can get what it is by executing: complete -p program_name
. Best to check first.
For some methods like apt-get
one can use only alias + load:
_load_comp_hack apt-get myalias
For others like mplayer
one need a function wrapper, as in e.g.:
myalias() { mplayer "$@"; }
|
+--- Could be messy
It is quite possible there is a better way to solve this, but has worked fine for my use. I mostly use it for wrapper scripts where I extend the functionality of the original program. Have not used it on aliases.
I do not feel to safe on this hack, but you could see if it works.
_load_comp_hack()
{
local cc=
# Make sure completion scripts are sourced.
# Report error if source fail.
if . "/usr/share/bash-completion/completions/$1" >/dev/null 2>&1; then
# Extract the completion function used by the "real" program.
if cc="$(complete -p "$1" | cut -d' ' -f3)"; then
# Add it to the alias
complete -F "$cc" "$2"
return 0
fi
fi
echo "bash-completion '$1' for '$2' not found."
}
_load_comp_hack mplayer mplad
_load_comp_hack apt-get z
| |
| +----- Alias, script or function
+------------- Real function
Some programs use more general completion like _longopt
, by which the
source file won't be located. Usually it is no need to source either, so a
simpler variant could be:
_load_comp_hack()
{
local cc=
if cc=$(complete -p "$1" | cut -d' ' -f3); then
complete -F "$cc" "$2"
fi
}
One problem here, IIRC, is that some completion scripts are not loaded until first run, as in first:
prog
tabtab. As an alternative perhaps add it as an else
if sourcing of file fails.
You want either:
insert-completions
ALT* for 'insert all completions'
With this, a dir containing files name 'aa ab ac ad'
ls a*
followed by alt + *
would complete to ls aa ab ac ad
Man page entry on binding:
insert-completions (M-*)
Insert all completions of the text before point that would have been generated by possible-completions.
glob-expand-word
On some systems the above will not work with wildchars, the following does work on such systems for me:
ctrlx, * (a two stroke combo)
Example:
I populated a dir with:
touch {a,b,c,d,e,f}{1,2,3,4,5,6,7,8,9,0}00{a,b,c,d,f,e}
I then ls *100*
followed by ctrl + x, *
, which turns my readline into:
ls a100a a100b a100c a100d a100e a100f b100a b100b b100c b100d b100e b100f c100a c100b c100c c100d c100e c100f d100a d100b d100c d100d d100e d100f e100a e100b e100c e100d e100e e100f f100a f100b f100c f100d f100e f100f
Man page entry for binding:
glob-expand-word (C-x *)
The word before point is treated as a pattern for pathname expansion, and the list of matching file names is inserted, replacing the word. If a numeric argument is supplied, a ‘*’ is appended before pathname expansion.
Man Page
Best Answer
May as well post it as an answer then. As a possible workaround, you can simply avoid breaking the loop and keep everything on the same line:
The above will allow you to complete
what
as expected.