[Bash-completion-commits] [SCM] bash-completion branch, master, updated. 1.3-512-g9717124

Igor Murzov e-mail at date.by
Sat Nov 5 16:48:05 UTC 2011


The following commit has been merged in the master branch:
commit 9717124ab7bad30b6d8ba02ef91850c6bb74dd63
Author: Igor Murzov <e-mail at date.by>
Date:   Sat Nov 5 20:13:05 2011 +0300

    service, _services: Make these work on Slackware GNU/Linux.

diff --git a/bash_completion b/bash_completion
index 1ef7030..629afbc 100644
--- a/bash_completion
+++ b/bash_completion
@@ -1039,12 +1039,26 @@ _gids()
 #
 _backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'
 
+# This function sets correct SysV init 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
@@ -1843,7 +1857,7 @@ _completion_loader()
     [[ $BASH_SOURCE == */* ]] && compdir="${BASH_SOURCE%/*}/completions"
 
     # Special case for init.d scripts.
-    if [[ $1 == /etc?(/rc.d)/init.d/* ]]; then
+    if [[ "$1" == $( _sysvdir )/* ]]; then
         . "$compdir/service" &>/dev/null && return 124 || return 1
     fi
 
diff --git a/completions/service b/completions/service
index f008770..1c7f710 100644
--- a/completions/service
+++ b/completions/service
@@ -15,9 +15,7 @@ _service()
     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
+        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" ) )
@@ -26,7 +24,7 @@ _service()
     return 0
 } &&
 complete -F _service service
-for svc in /etc/init.d/!($_backup_glob) /etc/rc.d/init.d/!($_backup_glob); do
+for svc in $( _sysvdir )/!($_backup_glob); do
     [ -x "$svc" ] && complete -F _service $svc
 done
 unset svc

-- 
bash-completion



More information about the Bash-completion-commits mailing list