Multi Level Bash Completion using existing completion functions?
I create开发者_如何学JAVAd a simple bash function : http://shr.im/ionyse-notify
I would like to add a little completion file.
I found two interesting functions :
- _known_hosts
- _user_at_host
How can I say that for the first argument, it should complete using _known_hosts and for the second using _user_at_host
#!/bin/bash
_send-msg_complete()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
COMPREPLY=( $(compgen -F _known_hosts -- $cur) )
elif [ $COMP_CWORD -eq 2 ]; then
COMPREPLY=( $(compgen -F _user_at_host -- $cur) )
fi
return 0
} &&
complete -F _send-msg_complete send-msg
Here is what I have, but it doesn't work. What's wrong ?
Actually, it is quite simple :
#!/bin/bash
_send-msg_complete()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ]; then
_known_hosts
elif [ $COMP_CWORD -eq 2 ]; then
_user_at_host
fi
return 0
} &&
complete -F _send-msg_complete send-msg
精彩评论