2010-06-09 22:19:05 +03:00
|
|
|
# service(8) and /etc/init.d/* completion
|
|
|
|
|
|
|
|
# This completes on a list of all available service scripts for the
|
|
|
|
# 'service' command and/or the SysV init.d directory, followed by
|
|
|
|
# that script's available commands
|
2011-04-05 00:35:51 +03:00
|
|
|
|
2011-04-12 20:11:39 +03:00
|
|
|
[[ -d /etc/init.d || -d /etc/rc.d/init.d ]] || have service || return
|
2011-04-05 00:35:51 +03:00
|
|
|
|
2010-06-09 22:19:05 +03:00
|
|
|
_service()
|
|
|
|
{
|
|
|
|
local cur prev sysvdir
|
|
|
|
|
|
|
|
COMPREPLY=()
|
2010-06-10 23:51:30 +02:00
|
|
|
_get_comp_words_by_ref cur prev
|
2010-06-09 22:19:05 +03:00
|
|
|
|
|
|
|
# don't complete past 2nd token
|
|
|
|
[ $COMP_CWORD -gt 2 ] && return 0
|
|
|
|
|
2010-07-01 20:21:35 +03:00
|
|
|
if [[ $COMP_CWORD -eq 1 && $prev == "service" ]]; then
|
2010-06-09 22:19:05 +03:00
|
|
|
_services
|
|
|
|
else
|
2011-02-05 12:06:53 +02:00
|
|
|
[ -d /etc/rc.d/init.d ] && \
|
|
|
|
sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
|
2010-06-09 22:19:05 +03:00
|
|
|
COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
|
|
|
|
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
|
|
|
|
$sysvdir/${prev##*/} 2>/dev/null`' -- "$cur" ) )
|
|
|
|
fi
|
|
|
|
|
|
|
|
return 0
|
|
|
|
} &&
|
|
|
|
complete -F _service service
|
2011-04-12 23:45:02 +03:00
|
|
|
for svc in /etc/init.d/!($_backup_glob) /etc/rc.d/init.d/!($_backup_glob); do
|
2011-04-12 20:10:09 +03:00
|
|
|
[ -x "$svc" ] && complete -F _service $svc
|
2010-06-28 19:54:16 +03:00
|
|
|
done
|
|
|
|
unset svc
|
2010-06-09 22:19:05 +03:00
|
|
|
|
|
|
|
# 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
|