2014-03-26 16:43:40 +01:00
|
|
|
#
|
|
|
|
# bash completion for ejabberdctl
|
|
|
|
#
|
2024-01-31 18:28:48 +01:00
|
|
|
# For installation and details see:
|
|
|
|
# https://docs.ejabberd.im/admin/guide/managing/#bash-completion
|
|
|
|
#
|
|
|
|
|
2014-03-26 16:43:40 +01:00
|
|
|
get_help()
|
|
|
|
{
|
2024-01-31 18:28:48 +01:00
|
|
|
local CACHE_BASE=/tmp/ejabberd_bash_completion
|
|
|
|
local DATESTRING=`date +%F-%H`
|
|
|
|
local CACHE=$CACHE_BASE.$DATESTRING
|
|
|
|
local CACHE_COMS=$CACHE.coms
|
|
|
|
local CACHE_TAGS=$CACHE.tags
|
|
|
|
if [[ ! -f $CACHE_COMS ]] ; then
|
|
|
|
rm -f $CACHE_BASE.*
|
|
|
|
[ -f $CACHE_COMS ] || ejabberdctl $CTLARGS | sed "s|\x1B\[[0-9]*m||g" | grep "^ [a-z]" | awk '{print $1}' | xargs >$CACHE_COMS
|
|
|
|
[ -f $CACHE_TAGS ] || ejabberdctl $CTLARGS help tags | sed "s|\x1B\[[0-9]*m||g" | grep "^ [a-z]" | awk '{print $1}' | xargs >$CACHE_TAGS
|
|
|
|
fi
|
|
|
|
if [[ $? == 2 ]] || [[ -f $CACHE_COMS ]] ; then
|
2014-03-26 16:43:40 +01:00
|
|
|
ISRUNNING=1
|
2024-01-31 18:28:48 +01:00
|
|
|
runningcommands=`cat $CACHE_COMS`
|
|
|
|
runningtags=`cat $CACHE_TAGS`
|
2014-03-26 16:43:40 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
_ejabberdctl()
|
|
|
|
{
|
|
|
|
local cur prev
|
|
|
|
local ISRUNNING=0
|
|
|
|
local runningcommands
|
|
|
|
|
|
|
|
COMPREPLY=()
|
|
|
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
|
|
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
|
|
|
|
2021-04-15 19:24:30 +02:00
|
|
|
local startcoms="start foreground foreground-quiet live debug etop iexdebug iexlive ping started stopped"
|
|
|
|
local startpars="--config-dir --config --ctl-config --logs --node --spool"
|
2014-03-26 16:43:40 +01:00
|
|
|
|
|
|
|
local i=1
|
|
|
|
local CTLARGS=""
|
|
|
|
while [ $i -lt $COMP_CWORD ] ; do
|
|
|
|
local PARAM="${COMP_WORDS[i]}"
|
|
|
|
i=$((i+1))
|
|
|
|
case $PARAM in
|
|
|
|
--*)
|
|
|
|
CTLARGS="--node ${COMP_WORDS[i]}"
|
|
|
|
i=$((i+1)) ;;
|
|
|
|
*) break ;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
case "${prev##*/}" in
|
|
|
|
ejabberdctl)
|
|
|
|
# This clause matches even when calling `/sbin/ejabberdctl` thanks to the ##*/ in the case
|
|
|
|
get_help
|
2016-04-15 15:35:57 +02:00
|
|
|
COMPREPLY=($(compgen -W "--node ${startpars} ${startcoms} ${runningcommands}" -- $cur))
|
2014-03-26 16:43:40 +01:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
start|live)
|
|
|
|
COMPREPLY=($(compgen -W "--node ${startpars}" -- $cur))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
debug)
|
|
|
|
COMPREPLY=($(compgen -W "--node" -- $cur))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
help)
|
|
|
|
get_help
|
2021-04-15 19:24:30 +02:00
|
|
|
COMPREPLY=($(compgen -W "${runningcommands} ${runningtags}" -- $cur))
|
2014-03-26 16:43:40 +01:00
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--node)
|
|
|
|
RUNNINGNODES=`epmd -names | grep name | awk '{print $2"@localhost"}' | xargs`
|
|
|
|
COMPREPLY=($(compgen -W "$RUNNINGNODES" -- $cur))
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--config|--ctl-config)
|
|
|
|
_filedir '?(u)cfg'
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
--config-dir|--logs|--spool)
|
|
|
|
_filedir
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
prev2="${COMP_WORDS[COMP_CWORD-2]}"
|
|
|
|
get_help
|
|
|
|
if [[ "$prev2" == --* ]]; then
|
2016-04-15 15:35:57 +02:00
|
|
|
COMPREPLY=($(compgen -W "--node ${startpars} ${startcoms} ${runningcommands}" -- $cur))
|
2014-03-26 16:43:40 +01:00
|
|
|
else
|
|
|
|
if [[ $ISRUNNING == 1 ]]; then
|
|
|
|
echo ""
|
|
|
|
ejabberdctl $CTLARGS help ${PARAM}
|
|
|
|
echo -n "${COMP_LINE}"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
return 0
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _ejabberdctl ejabberdctl
|
|
|
|
|
|
|
|
# Local variables:
|
|
|
|
# mode: shell-script
|
|
|
|
# sh-basic-offset: 4
|
|
|
|
# sh-indent-comment: t
|
|
|
|
# indent-tabs-mode: nil
|
|
|
|
# End:
|
|
|
|
# ex: ts=4 sw=4 et filetype=sh
|