summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Murzov <e-mail@date.by>2011-11-07 02:45:33 +0300
committerIgor Murzov <e-mail@date.by>2011-11-07 02:53:25 +0300
commitb03435fcc2e8a1f3ea2f72878e202f3a56bfc8de (patch)
tree9443e4b9bc0e22635c098ef83d382ef16c3e3ba5
parent01477d9c9e43c04bb33e59b7c62f938ba172a33b (diff)
downloadbash-completion-service.tar.gz
Add and use _sysvdirs() function that sets correct SysV init directory.service
This function allows distros to fine tune their init directory location, as simple checking for directories presence is not always sufficient.
-rw-r--r--bash_completion11
-rw-r--r--completions/service26
2 files changed, 25 insertions, 12 deletions
diff --git a/bash_completion b/bash_completion
index 6d3ffe2f..d96a7770 100644
--- a/bash_completion
+++ b/bash_completion
@@ -106,6 +106,17 @@ _userland()
[[ $userland == $1 ]]
}
+# This function sets correct SysV init directory
+#
+_sysvdirs()
+{
+ sysvdirs=( )
+ [[ -d /etc/rc.d/init.d ]] && sysvdirs+=( /etc/rc.d/init.d )
+ [[ -d /etc/init.d ]] && sysvdirs+=( /etc/init.d )
+ # Slackware uses /etc/rc.d
+ [[ -f /etc/slackware-version ]] && sysvdirs=( /etc/rc.d )
+}
+
# This function checks whether we have a given program on the system.
#
_have()
diff --git a/completions/service b/completions/service
index bccb17cd..7bcde8ca 100644
--- a/completions/service
+++ b/completions/service
@@ -4,13 +4,12 @@
#
_services()
{
- local sysvdir famdir
- [ -d /etc/rc.d/init.d ] && sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
- famdir=/etc/xinetd.d
+ local sysvdirs famdir=/etc/xinetd.d
+ _sysvdirs
local restore_nullglob=$(shopt -p nullglob); shopt -s nullglob
- COMPREPLY=( $( printf '%s\n' $sysvdir/!($_backup_glob|functions) ) )
+ COMPREPLY=( $( printf '%s\n' ${sysvdirs[0]}/!($_backup_glob|functions) ) )
if [ -d $famdir ]; then
COMPREPLY+=( $( printf '%s\n' $famdir/!($_backup_glob) ) )
@@ -21,7 +20,7 @@ _services()
COMPREPLY+=( $( systemctl list-units --full --all 2>/dev/null | \
awk '$1 ~ /\.service$/ { sub("\\.service$", "", $1); print $1 }' ) )
- COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@($sysvdir|$famdir)/}' -- "$cur" ) )
+ COMPREPLY=( $( compgen -W '${COMPREPLY[@]#@(${sysvdirs[0]}|$famdir)/}' -- "$cur" ) )
}
# This completes on a list of all available service scripts for the
@@ -39,20 +38,23 @@ _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 sysvdirs
+ _sysvdirs
COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
- $sysvdir/${prev##*/} 2>/dev/null` start stop' -- "$cur" ) )
+ ${sysvdirs[0]}/${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
+
+_sysvdirs
+for svcdir in ${sysvdirs[@]}; do
+ for svc in $svcdir/!($_backup_glob); do
+ [ -x "$svc" ] && complete -F _service $svc
+ done
done
-unset svc
+unset svc svcdir sysvdirs
# ex: ts=4 sw=4 et filetype=sh