Skip to content

Commit 9b443a9

Browse files
authored
Merge pull request #965 from scop/refactor/util-func-cmds
refactor: adjust to util/xfunc primary command convention
2 parents aebb073 + 643886c commit 9b443a9

File tree

13 files changed

+133
-56
lines changed

13 files changed

+133
-56
lines changed

completions/aspell

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

33
_comp_cmd_aspell__dictionary()
44
{
5-
local datadir aspell=${1:-aspell}
5+
local datadir aspell=$1
66
datadir=$("$aspell" config data-dir 2>/dev/null || echo /usr/lib/aspell)
77
# First, get aliases (dicts dump does not list them)
88
COMPREPLY=($datadir/*.alias)

completions/carton

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
_comp_cmd_carton__commands()
44
{
5-
local cmds=$("${1:-carton}" usage 2>&1 |
5+
local cmds=$("$1" usage 2>&1 |
66
command sed -ne '/.*command.* is one of/{n;p;q;}')
77
_comp_compgen -aF $' \t\n,' -- -W "$cmds"
88
}
99

1010
_comp_cmd_carton__command_help()
1111
{
12-
local help=$(PERLDOC_PAGER=cat PERLDOC=-otext "${1:-carton}" -h "$2" 2>&1)
12+
local help=$(PERLDOC_PAGER=cat PERLDOC=-otext "$1" -h "$2" 2>&1)
1313
_comp_compgen -a -- -W '$help'
1414
}
1515

completions/iconv

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@
33
# @since 2.12
44
_comp_xfunc_iconv_charsets()
55
{
6-
COMPREPLY+=($(compgen -X ... -W '$("${1:-iconv}" -l | \
7-
command sed -e "s@/*\$@@" -e "s/[,()]//g")' -- "$cur"))
6+
_comp_cmd_iconv__charsets iconv
7+
}
8+
9+
# @deprecated 2.12 use `_comp_xfunc_iconv_charsets` instead
10+
_iconv_charsets()
11+
{
12+
_comp_cmd_iconv__charsets "${1:-iconv}"
813
}
914

10-
_comp_deprecate_func 2.12 _iconv_charsets _comp_xfunc_iconv_charsets
15+
_comp_cmd_iconv__charsets()
16+
{
17+
COMPREPLY+=($(compgen -X ... -W '$("$1" -l | \
18+
command sed -e "s@/*\$@@" -e "s/[,()]//g")' -- "$cur"))
19+
}
1120

1221
_comp_cmd_iconv()
1322
{
@@ -22,7 +31,7 @@ _comp_cmd_iconv()
2231
return
2332
;;
2433
--from-code | --to-code | -${noargopts}[ft])
25-
_comp_xfunc_iconv_charsets "$1"
34+
_comp_cmd_iconv__charsets "$1"
2635
return
2736
;;
2837
--output | -${noargopts}o)

completions/mysql

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ _comp_cmd_mysql()
1818
local cur prev words cword was_split comp_args
1919
_comp_initialize -s -- "$@" || return
2020

21+
# Prefer `mysqlshow` in the same dir as the command
22+
local pathcmd
23+
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
24+
2125
local noargopts='!(-*|*[uDhSPeI]*)'
2226
# shellcheck disable=SC2254
2327
case $prev in

completions/perl

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
_comp_cmd_perl__helper()
44
{
55
COMPREPLY=($(compgen -P "$prefix" -W \
6-
"$("${2:-perl}" "${BASH_SOURCE[0]%/*}/../helpers/perl" "$1" "$cur")" \
6+
"$("${1:-perl}" "${BASH_SOURCE[0]%/*}/../helpers/perl" "$2" "$cur")" \
77
-- "$cur"))
88
[[ $1 == functions ]] || _comp_ltrim_colon_completions "$prefix$cur"
99
}
@@ -41,7 +41,7 @@ _comp_cmd_perl()
4141
temp="${cur#-}"
4242
prefix+=${cur%"$temp"}
4343
cur="$temp"
44-
_comp_cmd_perl__helper modules "$1"
44+
_comp_cmd_perl__helper "$1" modules
4545
return
4646
;;
4747
-*V)
@@ -61,7 +61,7 @@ _comp_cmd_perl()
6161
temp="${cur#:}"
6262
prefix=$prefix${cur%"$temp"}
6363
cur="Devel::$temp"
64-
_comp_cmd_perl__helper modules "$1"
64+
_comp_cmd_perl__helper "$1" modules
6565
fi
6666
;;
6767
esac
@@ -106,8 +106,9 @@ _comp_cmd_perldoc()
106106
prefix=$prev
107107
fi
108108

109-
local perl="${1%doc}"
110-
[[ $perl == "$1" ]] || ! type "$perl" &>/dev/null && perl=
109+
# Prefer `perl` in the same dir in utility functions
110+
local pathcmd
111+
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
111112

112113
case $prev in
113114
-*[hVnoMwL])
@@ -118,7 +119,7 @@ _comp_cmd_perldoc()
118119
return
119120
;;
120121
-*f)
121-
_comp_cmd_perl__helper functions "$perl"
122+
_comp_cmd_perl__helper "" functions
122123
return
123124
;;
124125
esac
@@ -128,7 +129,7 @@ _comp_cmd_perldoc()
128129
else
129130
# return available modules (unless it is clearly a file)
130131
if [[ $cur != @(*/|[.~])* ]]; then
131-
_comp_cmd_perl__helper perldocs "$perl"
132+
_comp_cmd_perl__helper "" perldocs
132133
if [[ $cur == p* ]]; then
133134
COMPREPLY+=($(compgen -W \
134135
'$(PERLDOC_PAGER=cat "$1" -u perl | \

completions/pydoc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ _comp_cmd_pydoc()
2323
_comp_compgen -- -W 'keywords topics modules'
2424

2525
if ! _comp_looks_like_path "$cur"; then
26-
local python=python
27-
[[ ${1##*/} == *3* ]] && python=python3
28-
_comp_xfunc python modules $python
26+
# Prefer python in the same dir for resolving modules
27+
local pathcmd
28+
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
29+
_comp_xfunc python modules
2930
fi
3031

3132
# Note that we don't do "pydoc modules" as it is known to hang on

completions/pylint

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ _comp_cmd_pylint__message_ids()
1010
# again later?
1111
local msgs="$(
1212
set -o pipefail
13-
${1:-pylint} --list-msgs-enabled 2>/dev/null |
13+
"$1" --list-msgs-enabled 2>/dev/null |
1414
command sed -ne "$filter" |
1515
command sed -ne 's/^[[:space:]]\{1,\}\([a-z-]\{6,\}\).*/\1/p' ||
16-
${1:-pylint} --list-msgs 2>/dev/null |
16+
"$1" --list-msgs 2>/dev/null |
1717
command sed -ne 's/^:\([a-z-]\{6,\}\).*/\1/p'
1818
)"
1919
_comp_delimited , -W "$msgs"

completions/pytest

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
_comp_cmd_pytest__option_choice_args()
44
{
5-
local modes=$("${2:-pytest}" "$1=bash-completion-nonexistent" 2>&1 |
5+
local modes=$("$1" "$2=bash-completion-nonexistent" 2>&1 |
66
command sed -e 's/[^[:space:][:alnum:]-]\{1,\}//g' \
77
-ne 's/.*choose from //p')
88
_comp_compgen -a -- -W '$modes'
@@ -87,7 +87,7 @@ _comp_cmd_pytest()
8787
return
8888
;;
8989
--dist | --vcr-record?(-mode))
90-
_comp_cmd_pytest__option_choice_args "$prev" "$1"
90+
_comp_cmd_pytest__option_choice_args "$1" "$prev"
9191
return
9292
;;
9393
esac

completions/python

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,22 @@
22

33
# @since 2.12
44
_comp_xfunc_python_modules()
5+
{
6+
local python=python
7+
[[ ${comp_args[0]##*/} == *3* ]] && python=python3
8+
_comp_cmd_python__modules "$python"
9+
}
10+
11+
# @deprecated 2.12 use `_comp_xfunc_python_modules` instead
12+
_python_modules()
13+
{
14+
_comp_cmd_python__modules "${1:-python}"
15+
}
16+
17+
_comp_cmd_python__modules()
518
{
619
COMPREPLY+=($(compgen -W \
7-
"$("${1:-python}" "${BASH_SOURCE[0]%/*}/../helpers/python" "$cur" \
20+
"$("$1" "${BASH_SOURCE[0]%/*}/../helpers/python" "$cur" \
821
2>/dev/null)" -- "$cur"))
922
}
1023

@@ -15,7 +28,6 @@ _comp_xfunc_python_warning_actions()
1528
${prefix:+-P "$prefix"}
1629
}
1730

18-
_comp_deprecate_func 2.12 _python_modules _comp_xfunc_python_modules
1931
_comp_deprecate_func 2.12 _python_warning_actions \
2032
_comp_xfunc_python_warning_actions
2133

@@ -39,7 +51,7 @@ _comp_cmd_python()
3951
return
4052
;;
4153
-${noargopts}m)
42-
_comp_xfunc_python_modules "$1"
54+
_comp_cmd_python__modules "$1"
4355
return
4456
;;
4557
-${noargopts}Q)

completions/rpm

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
# @since 2.12
66
_comp_xfunc_rpm_installed_packages()
7+
{
8+
_comp_cmd_rpm__installed_packages rpm
9+
}
10+
11+
_comp_cmd_rpm__installed_packages()
712
{
813
if [[ -r /var/log/rpmpkgs &&
914
/var/log/rpmpkgs -nt /var/lib/rpm/Packages ]]; then
@@ -38,13 +43,20 @@ _comp_cmd_rpm__macros()
3843
-- "$cur"))
3944
}
4045

46+
# shellcheck disable=SC2120
4147
_comp_cmd_rpm__buildarchs()
4248
{
4349
COMPREPLY=($(compgen -W "$("${1:-rpm}" --showrc | command sed -ne \
4450
's/^\s*compatible\s\s*build\s\s*archs\s*:\s*\(.*\)/\1/ p')" \
4551
-- "$cur"))
4652
}
4753

54+
# shellcheck disable=SC2120
55+
_comp_cmd_rpm__configdir()
56+
{
57+
cfgdir=$("${1:-rpm}" --eval '%{_rpmconfigdir}' 2>/dev/null)
58+
}
59+
4860
# rpm(8) completion
4961
#
5062
_comp_cmd_rpm()
@@ -147,7 +159,7 @@ _comp_cmd_rpm()
147159
_comp_compgen -- -W '"${opts[@]}" --allmatches --noscripts
148160
--notriggers --nodeps --test --repackage'
149161
else
150-
_comp_xfunc_rpm_installed_packages "$1"
162+
_comp_cmd_rpm__installed_packages "$1"
151163
fi
152164
;;
153165
-q* | --query)
@@ -190,7 +202,7 @@ _comp_cmd_rpm()
190202
--whatrecommends --whatrequires --whatsuggests
191203
--whatsupplements'
192204
elif [[ ${words[*]} != *\ -@(*([^ -])a|-all )* ]]; then
193-
_comp_xfunc_rpm_installed_packages "$1"
205+
_comp_cmd_rpm__installed_packages "$1"
194206
fi
195207
fi
196208
;;
@@ -216,14 +228,14 @@ _comp_cmd_rpm()
216228
elif [[ ${words[*]} == *\ -@(*([^ -])p|-package )* ]]; then
217229
_comp_compgen_filedir '[rs]pm'
218230
else
219-
_comp_xfunc_rpm_installed_packages "$1"
231+
_comp_cmd_rpm__installed_packages "$1"
220232
fi
221233
;;
222234
--resign | --addsign | --delsign)
223235
_comp_compgen_filedir '[rs]pm'
224236
;;
225237
--setperms | --setgids)
226-
_comp_xfunc_rpm_installed_packages "$1"
238+
_comp_cmd_rpm__installed_packages "$1"
227239
;;
228240
--import | --dbpath | --root)
229241
if [[ $cur == -* ]]; then
@@ -242,30 +254,33 @@ _comp_cmd_rpmbuild()
242254
local cur prev words cword was_split comp_args
243255
_comp_initialize -s -- "$@" || return
244256

245-
local rpm="${1%build*}"
246-
[[ $rpm == "$1" ]] || ! type "$rpm" &>/dev/null && rpm=
247-
248257
local noargopts='!(-*|*[rED]*)'
249-
# shellcheck disable=SC2254
258+
# shellcheck disable=SC2119,SC2254
250259
case $prev in
251260
--buildroot | --root | --dbpath | -${noargopts}r)
252261
_comp_compgen_filedir -d
253262
return
254263
;;
264+
--target | --eval | -${noargopts}E | --buildpolicy)
265+
# Prefer `rpm` in the same dir in utility functions
266+
local pathcmd
267+
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
268+
;;&
255269
--target)
256-
_comp_cmd_rpm__buildarchs "$rpm"
270+
_comp_cmd_rpm__buildarchs
257271
return
258272
;;
259273
--eval | -${noargopts}E)
260-
_comp_cmd_rpm__macros "$rpm"
274+
_comp_cmd_rpm__macros
261275
return
262276
;;
263277
--macros | --rcfile)
264278
_comp_compgen_filedir
265279
return
266280
;;
267281
--buildpolicy)
268-
local cfgdir=$("$rpm" --eval '%{_rpmconfigdir}' 2>/dev/null)
282+
local cfgdir
283+
_comp_cmd_rpm__configdir
269284
if [[ $cfgdir ]]; then
270285
COMPREPLY=($(compgen -W "$(command ls "$cfgdir" 2>/dev/null |
271286
command sed -ne 's/^brp-//p')" -- "$cur"))

0 commit comments

Comments
 (0)