Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -2207,18 +2207,25 @@ _comp_compgen_xinetd_services()
fi
}

# This function completes on SysV init services
#
# @since 2.18
_comp_compgen_sysv_services()
{
local sysvdirs
_comp_sysvdirs &&
_comp_compgen -U sysvdirs -C "${sysvdirs[0]}" -- \
-fX "@($_comp_backup_glob|functions|*.sh|README*|*/*)"
}

# This function completes on services
#
# @return 0 if at least one completion is generated, or 1 otherwise.
# @since 2.12
_comp_compgen_services()
{
local sysvdirs
_comp_sysvdirs || return 1

local status=1
_comp_compgen -U sysvdirs -C "${sysvdirs[0]}" -- -f -X "@($_comp_backup_glob|functions|README)" &&
status=0
_comp_compgen_sysv_services && status=0

local _generated=$({
systemctl list-units --full --all ||
Expand Down
17 changes: 8 additions & 9 deletions completions-core/invoke-rc.d.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ _comp_cmd_invoke_rc_d()
local cur prev words cword comp_args
_comp_initialize -- "$@" || return

local sysvdir options

[[ -d /etc/rc.d/init.d ]] && sysvdir=/etc/rc.d/init.d ||
sysvdir=/etc/init.d

local options
options=(--help --quiet --force --try-anyway --disclose-deny --query
--no-fallback)

Expand All @@ -21,12 +17,15 @@ _comp_cmd_invoke_rc_d()
local exclude="@(${words[*]})"
_comp_unlocal IFS
_comp_compgen -- -W '"${options[@]}"' -X "$exclude"
# shellcheck disable=SC2154
_comp_compgen -aC "$sysvdir" -- -f -X "@(README*|*.sh|$_comp_backup_glob)"
elif [[ -x $sysvdir/$prev ]]; then
_comp_compgen -a sysv_services
return
fi

local sysvdirs
if _comp_sysvdirs && [[ -x ${sysvdirs[0]}/$prev ]]; then
_comp_compgen_split -- "$(command sed -e 'y/|/ /' \
-ne 's/^.*Usage:[ ]*[^ ]*[ ]*{*\([^}"]*\).*$/\1/p' \
"$sysvdir/$prev")"
"${sysvdirs[0]}/$prev")"
else
COMPREPLY=()
fi
Expand Down
9 changes: 2 additions & 7 deletions completions-core/update-rc.d.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ _comp_cmd_update_rc_d()
local cur prev words cword comp_args
_comp_initialize -- "$@" || return

local sysvdir services options

[[ -d /etc/rc.d/init.d ]] && sysvdir=/etc/rc.d/init.d ||
sysvdir=/etc/init.d

# shellcheck disable=SC2154
_comp_compgen -v services -C "$sysvdir" -- -f -X "@(README*|*.sh|$_comp_backup_glob)"
local services options
_comp_compgen -v services sysv_services
options=(-f -n)

if [[ $cword -eq 1 || $prev == -* ]]; then
Expand Down