Skip to content

Commit 1930f81

Browse files
authored
Merge pull request #964 from akinomyoga/filedir
style(_comp_compgen): call `_comp_compgen_filedir` directly
2 parents 7f5fa3d + eb90bc7 commit 1930f81

File tree

317 files changed

+722
-712
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

317 files changed

+722
-712
lines changed

bash_completion

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ _comp_split()
437437
# [-alR|-v arr|-c cur] to the child calls of `_comp_compgen` in
438438
# `_comp_compgen_NAME`.
439439
#
440+
# @remarks When no options are supplied to _comp_compgen, `_comp_compgen NAME
441+
# args` is equivalent to the direct call `_comp_compgen_NAME args`. As the
442+
# direct call is slightly more efficient, the direct call is preferred over
443+
# calling it through `_comp_compgen`.
444+
#
440445
# @remarks Design `_comp_compgen_NAME`: a function that produce completions can
441446
# be defined with the name _comp_compgen_NAME. The function is supposed to
442447
# generate completions by calling `_comp_compgen`. To reflect the options
@@ -853,47 +858,52 @@ _comp_compgen_filedir()
853858
_comp_compgen_tilde && return
854859

855860
local -a toks
856-
local arg=${1-}
861+
local _arg=${1-}
857862

858-
if [[ $arg == -d ]]; then
863+
if [[ $_arg == -d ]]; then
859864
_comp_compgen -v toks -- -d
860865
else
861866
local ret
862867
_comp_quote_compgen "${cur-}"
863-
local quoted=$ret
868+
local _quoted=$ret
869+
_comp_unlocal ret
864870

865871
# Munge xspec to contain uppercase version too
866872
# https://lists.gnu.org/archive/html/bug-bash/2010-09/msg00036.html
867873
# news://news.gmane.io/4C940E1C.1010304@case.edu
868-
local xspec=${arg:+"!*.@($arg|${arg^^})"} plusdirs=()
874+
local _xspec=${_arg:+"!*.@($_arg|${_arg^^})"} _plusdirs=()
869875

870876
# Use plusdirs to get dir completions if we have a xspec; if we don't,
871877
# there's no need, dirs come along with other completions. Don't use
872878
# plusdirs quite yet if fallback is in use though, in order to not ruin
873879
# the fallback condition with the "plus" dirs.
874-
local opts=(-f -X "$xspec")
875-
[[ $xspec ]] && plusdirs=(-o plusdirs)
880+
local _opts=(-f -X "$_xspec")
881+
[[ $_xspec ]] && _plusdirs=(-o plusdirs)
876882
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} ||
877-
! ${plusdirs-} ]] ||
878-
opts+=("${plusdirs[@]}")
883+
! ${_plusdirs-} ]] ||
884+
_opts+=("${_plusdirs[@]}")
879885

880-
_comp_compgen -v toks -c "$quoted" -- "${opts[@]}"
886+
_comp_compgen -v toks -c "$_quoted" -- "${_opts[@]}"
881887

882888
# Try without filter if it failed to produce anything and configured to
883889
[[ ${BASH_COMPLETION_FILEDIR_FALLBACK-${COMP_FILEDIR_FALLBACK-}} &&
884-
$arg && ${#toks[@]} -lt 1 ]] &&
885-
_comp_compgen -av toks -c "$quoted" -- -f ${plusdirs+"${plusdirs[@]}"}
890+
$_arg && ${#toks[@]} -lt 1 ]] &&
891+
_comp_compgen -av toks -c "$_quoted" -- \
892+
-f ${_plusdirs+"${_plusdirs[@]}"}
886893
fi
887894

888895
if ((${#toks[@]} != 0)); then
889-
# 2>/dev/null for direct invocation, e.g. in the _comp_compgen_filedir unit test
896+
# 2>/dev/null for direct invocation, e.g. in the _comp_compgen_filedir
897+
# unit test
890898
compopt -o filenames 2>/dev/null
891899
fi
892900

893901
# Note: bash < 4.4 has a bug that all the elements are connected with
894902
# ${v-"${a[@]}"} when IFS does not contain whitespace.
895903
local IFS=$' \t\n'
896-
_comp_compgen_set ${toks[@]+"${toks[@]}"}
904+
local -a _tmp=(${toks[@]+"${toks[@]}"})
905+
_comp_unlocal toks
906+
_comp_compgen_set ${_tmp[@]+"${_tmp[@]}"}
897907
} # _comp_compgen_filedir()
898908

899909
# This function splits $cur=--foo=bar into $prev=--foo, $cur=bar, making it
@@ -1154,7 +1164,7 @@ _comp_initialize()
11541164
;;
11551165
esac
11561166
cur=${cur##"$redir"}
1157-
_comp_compgen filedir "$xspec"
1167+
_comp_compgen_filedir "$xspec"
11581168
return 1
11591169
fi
11601170

completions/2to3

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ _comp_cmd_2to3()
1919
return
2020
;;
2121
-o | --output-dir)
22-
_comp_compgen filedir -d
22+
_comp_compgen_filedir -d
2323
return
2424
;;
2525
esac
@@ -32,7 +32,7 @@ _comp_cmd_2to3()
3232
return
3333
fi
3434

35-
_comp_compgen filedir py
35+
_comp_compgen_filedir py
3636
} &&
3737
complete -F _comp_cmd_2to3 2to3
3838

completions/7z

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ _comp_cmd_7z()
119119
2>/dev/null | tail -n+2)")" -- "$cur"))
120120
compopt -o filenames
121121
else
122-
_comp_compgen filedir
122+
_comp_compgen_filedir
123123
fi
124124
fi
125125
} &&

completions/_adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ _comp_cmd_adb()
2020
return
2121
;;
2222
-f)
23-
_comp_compgen filedir
23+
_comp_compgen_filedir
2424
return
2525
;;
2626
esac

completions/_chsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ _comp_cmd_chsh()
2222
return
2323
;;
2424
-R | --root)
25-
_comp_compgen filedir -d
25+
_comp_compgen_filedir -d
2626
return
2727
;;
2828
-s | --shell)

completions/_hexdump

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _comp_cmd_hexdump()
1313
return
1414
;;
1515
-f)
16-
_comp_compgen filedir
16+
_comp_compgen_filedir
1717
return
1818
;;
1919
esac
@@ -25,7 +25,7 @@ _comp_cmd_hexdump()
2525
return
2626
fi
2727

28-
_comp_compgen filedir
28+
_comp_compgen_filedir
2929
} &&
3030
complete -F _comp_cmd_hexdump hexdump hd
3131

completions/_hwclock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ _comp_cmd_hwclock()
1313
return
1414
;;
1515
-f | --rtc | --adjfile)
16-
_comp_compgen filedir
16+
_comp_compgen_filedir
1717
return
1818
;;
1919
esac

completions/_mock

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ _comp_cmd_mock()
3232
return
3333
;;
3434
--configdir | --resultdir)
35-
_comp_compgen filedir -d
35+
_comp_compgen_filedir -d
3636
return
3737
;;
3838
--spec)
39-
_comp_compgen filedir spec
39+
_comp_compgen_filedir spec
4040
return
4141
;;
4242
--target)
@@ -61,7 +61,7 @@ _comp_cmd_mock()
6161
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
6262
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
6363
else
64-
_comp_compgen filedir '@(?(no)src.r|s)pm'
64+
_comp_compgen_filedir '@(?(no)src.r|s)pm'
6565
fi
6666
} &&
6767
complete -F _comp_cmd_mock mock

completions/_mount.linux

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ _comp_cmd_mount()
2828
return
2929
;;
3030
--bind | -B | --rbind | -R)
31-
_comp_compgen filedir -d
31+
_comp_compgen_filedir -d
3232
return
3333
;;
3434
-p | --pass-fd)

completions/_repomanage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ _comp_cmd_repomanage()
1616
COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur"))
1717
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
1818
else
19-
_comp_compgen filedir -d
19+
_comp_compgen_filedir -d
2020
fi
2121
} &&
2222
complete -F _comp_cmd_repomanage repomanage

0 commit comments

Comments
 (0)