Also make this completions work on Slackware GNU/Linux. --- bash_completion | 48 ++++++++++++++++++++++++++++++++++++++++++------ completions/service | 40 ---------------------------------------- 2 files changed, 42 insertions(+), 46 deletions(-) delete mode 100644 completions/service
diff --git a/bash_completion b/bash_completion index 84bbe80..7df5ca9 100644 --- a/bash_completion +++ b/bash_completion @@ -1036,12 +1036,26 @@ _gids() # _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))' +# This function sets correct SysV init.d directory +# +_sysvdir() +{ + if [ -f /etc/slackware-version ]; then + # Slackware uses /etc/rc.d + echo /etc/rc.d + elif [ -d /etc/rc.d/init.d ]; then + echo /etc/rc.d/init.d + else + echo /etc/init.d + fi +} + # This function completes on services # _services() { local sysvdir famdir - [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d + sysvdir=$( _sysvdir ) famdir=/etc/xinetd.d local restore_nullglob=$(shopt -p nullglob); shopt -s nullglob @@ -1060,6 +1074,33 @@ _services() COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- "$cur" ) ) } +# 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 +_service() +{ + local cur prev words cword + _init_completion || return + + # don't complete past 2nd token + [ $cword -gt 2 ] && return 0 + + if [[ $cword -eq 1 && $prev == ?(*/)service ]]; then + _services + else + local sysvdir=$( _sysvdir ) + COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \ + -ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \ + $sysvdir/${prev##*/} 2>/dev/null` start stop' -- "$cur" ) ) + fi +} +complete -F _service service +for svc in $( _sysvdir )/!($_backup_glob); do + [ -x "$svc" ] && complete -F _service $svc +done +unset svc + + # This function completes on modules # _modules() @@ -1817,11 +1858,6 @@ _completion_loader() local compdir=./completions [[ $BASH_SOURCE == */* ]] && compdir="${BASH_SOURCE%/*}/completions" - # Special case for init.d scripts. - if [[ $1 == /etc?(/rc.d)/init.d/* ]]; then - . "$compdir/service" &>/dev/null && return 124 || return 1 - fi - # Try basename. . "$compdir/${1##*/}" &>/dev/null && return 124 diff --git a/completions/service b/completions/service deleted file mode 100644 index 51257ab..0000000 --- a/completions/service +++ /dev/null @@ -1,40 +0,0 @@ -# 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 - -_service() -{ - local cur prev words cword - _init_completion || return - - # don't complete past 2nd token - [ $cword -gt 2 ] && return 0 - - if [[ $cword -eq 1 && $prev == ?(*/)service ]]; then - _services - else - local sysvdir - [ -d /etc/rc.d/init.d ] && \ - sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d - COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \ - -ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \ - $sysvdir/${prev##*/} 2>/dev/null` start stop' -- "$cur" ) ) - fi - - return 0 -} && -complete -F _service service -for svc in /etc/init.d/!($_backup_glob) /etc/rc.d/init.d/!($_backup_glob); do - [ -x "$svc" ] && complete -F _service $svc -done -unset svc - -# 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 -- 1.7.4.4 _______________________________________________ Bash-completion-devel mailing list Bash-completion-devel@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/bash-completion-devel