Chet Ramey wrote:
Matthew Woehlke wrote:
I have a function 'cs' that roughly looks like 'cd /some/prefix/$*',
that I would like to have completion for. Any tips? (For some reason,
non-trivial completions never seem to want to work for me :-(.)
Why not write a shell function that prefixes the right directory to
the word to be completed, runs compgen, and strips the prefix from the
generated list of completions?
Because "for some reason, non-trivial completions never seem to want to
work for me"?
Sigh. Ok, after trying for entirely too long, this seems to be working:
completeme() {
local i=0
while read l; do
COMPREPLY[$((++i))]="$l"
done < <(
cd /some/prefix
w="${COMP_WORDS[1]}"
if [ -n "$w" ]
then compgen -d "$w"
else compgen -d
fi
)
}
complete -F completeme cs
...and yet, seems entirely too difficult.
Why doesn't 'complete -C' work? Why does 'compgen -d ""' produce no
output? Shouldn't it produce the same output as 'compgen -d'?
--
Matthew
For great justice!! -- Captain (Zero Wing)