Skip to content

Commit 2dfc8ad

Browse files
authored
Merge pull request #735 from akinomyoga/refactor-function-names
refactor(bash_completion): rename functions `_userland`, `_sysdirs`, `_have`, and `_rl_enabled`
2 parents 6f1bbda + fffc188 commit 2dfc8ad

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

bash_completion

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,18 @@ complete -b builtin
9494

9595
# Check if we're running on the given userland
9696
# @param $1 userland to check for
97-
_userland()
97+
_comp_userland()
9898
{
9999
local userland=$(uname -s)
100100
[[ $userland == @(Linux|GNU/*) ]] && userland=GNU
101101
[[ $userland == "$1" ]]
102102
}
103103

104+
_comp_deprecate_func _userland _comp_userland
105+
104106
# This function sets correct SysV init directories
105107
#
106-
_sysvdirs()
108+
_comp_sysvdirs()
107109
{
108110
sysvdirs=()
109111
[[ -d /etc/rc.d/init.d ]] && sysvdirs+=(/etc/rc.d/init.d)
@@ -113,32 +115,38 @@ _sysvdirs()
113115
return 0
114116
}
115117

118+
_comp_deprecate_func _sysvdirs _comp_sysvdirs
119+
116120
# This function checks whether we have a given program on the system.
117121
#
118-
_have()
122+
_comp_have_command()
119123
{
120124
# Completions for system administrator commands are installed as well in
121125
# case completion is attempted via `sudo command ...'.
122126
PATH=$PATH:/usr/sbin:/sbin:/usr/local/sbin type $1 &>/dev/null
123127
}
124128

129+
_comp_deprecate_func _have _comp_have_command
130+
125131
# Backwards compatibility for compat completions that use have().
126132
# @deprecated should no longer be used; generally not needed with dynamically
127-
# loaded completions, and _have is suitable for runtime use.
133+
# loaded completions, and _comp_have_command is suitable for runtime use.
128134
have()
129135
{
130136
unset -v have
131-
_have $1 && have=yes
137+
_comp_have_command $1 && have=yes
132138
}
133139

134140
# This function checks whether a given readline variable
135141
# is `on'.
136142
#
137-
_rl_enabled()
143+
_comp_readline_variable_on()
138144
{
139145
[[ $(bind -v) == *$1+([[:space:]])on* ]]
140146
}
141147

148+
_comp_deprecate_func _rl_enabled _comp_readline_variable_on
149+
142150
# This function shell-quotes the argument
143151
quote()
144152
{
@@ -1439,7 +1447,7 @@ _xinetd_services()
14391447
_services()
14401448
{
14411449
local sysvdirs
1442-
_sysvdirs
1450+
_comp_sysvdirs
14431451

14441452
_comp_expand_glob COMPREPLY '${sysvdirs[0]}/!($_comp_backup_glob|functions|README)'
14451453

@@ -1475,7 +1483,7 @@ _service()
14751483
[[ -e /etc/mandrake-release ]] && _xinetd_services
14761484
else
14771485
local IFS=$'\n' sysvdirs
1478-
_sysvdirs
1486+
_comp_sysvdirs
14791487
COMPREPLY=($(compgen -W '`command sed -e "y/|/ /" \
14801488
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
14811489
${sysvdirs[0]}/${prev##*/} 2>/dev/null` start stop' -- "$cur"))
@@ -1486,7 +1494,7 @@ _service()
14861494
_comp__init_set_up_service_completions()
14871495
{
14881496
local sysvdirs svc svcdir
1489-
_sysvdirs
1497+
_comp_sysvdirs
14901498
for svcdir in "${sysvdirs[@]}"; do
14911499
for svc in "$svcdir"/!($_comp_backup_glob); do
14921500
[[ -x $svc ]] && complete -F _service "$svc"
@@ -2065,8 +2073,9 @@ _cd()
20652073
return
20662074
fi
20672075

2068-
local -r mark_dirs=$(_rl_enabled mark-directories && echo y)
2069-
local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y)
2076+
local mark_dirs='' mark_symdirs=''
2077+
_comp_readline_variable_on mark-directories && mark_dirs=y
2078+
_comp_readline_variable_on mark-symlinked-directories && mark_symdirs=y
20702079

20712080
# we have a CDPATH, so loop on its contents
20722081
for i in ${CDPATH//:/$'\n'}; do

completions/aptitude

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Debian aptitude(1) completion -*- shell-script -*-
22

3-
if _have grep-status; then
3+
if _comp_have_command grep-status; then
44
_comp_dpkg_hold_packages()
55
{
66
grep-status -P -e "^$1" -a -FStatus 'hold' -n -s Package

completions/arch

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Try to detect whether this is the mailman "arch" to avoid installing
44
# it for the coreutils/util-linux-ng one.
5-
_have mailmanctl &&
5+
_comp_have_command mailmanctl &&
66
_arch()
77
{
88
local cur prev words cword split

completions/dpkg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This function is required by _dpkg and _dpkg-reconfigure -*- shell-script -*-
22

3-
if _have grep-status; then
3+
if _comp_have_command grep-status; then
44
_comp_xfunc_dpkg_installed_packages()
55
{
66
grep-status -P -e "^${1-}" -a -FStatus 'ok installed' -n -s Package

completions/ifup

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Red Hat & Debian GNU/Linux if{up,down} completion -*- shell-script -*-
22

3-
_userland GNU || return 1
3+
_comp_userland GNU || return 1
44

55
_ifupdown()
66
{

0 commit comments

Comments
 (0)