@@ -4,7 +4,6 @@ _comp_deprecate_func _userland _comp_userland
44_comp_deprecate_func _sysvdirs _comp_sysvdirs
55_comp_deprecate_func _have _comp_have_command
66_comp_deprecate_func _rl_enabled _comp_readline_variable_on
7- _comp_deprecate_func _init_completion _comp_initialize
87_comp_deprecate_func _command_offset _comp_command_offset
98_comp_deprecate_func _command _comp_command
109_comp_deprecate_func _root_command _comp_root_command
@@ -178,6 +177,59 @@ _realcommand()
178177 return $rc
179178}
180179
180+ # Initialize completion and deal with various general things: do file
181+ # and variable completion where appropriate, and adjust prev, words,
182+ # and cword as if no redirections exist so that completions do not
183+ # need to deal with them. Before calling this function, make sure
184+ # cur, prev, words, and cword are local, ditto split if you use -s.
185+ #
186+ # Options:
187+ # -n EXCLUDE Passed to _comp_get_words -n with redirection chars
188+ # -e XSPEC Passed to _filedir as first arg for stderr redirections
189+ # -o XSPEC Passed to _filedir as first arg for other output redirections
190+ # -i XSPEC Passed to _filedir as first arg for stdin redirections
191+ # -s Split long options with _split_longopt, implies -n =
192+ # @var[out] cur Reconstructed current word
193+ # @var[out] prev Reconstructed previous word
194+ # @var[out] words Reconstructed words
195+ # @var[out] cword Current word index in `words`
196+ # @var[out,opt] split When "-s" is specified, `"true"/"false"` is set depending
197+ # on whether the split happened.
198+ # @return True (0) if completion needs further processing,
199+ # False (> 0) no further processing is necessary.
200+ #
201+ # @deprecated Use the new interface `_comp_initialize`. The new interface
202+ # supports the same set of options. The new interface receives additional
203+ # arguments $1 (command name), $2 (part of current word before the cursor), and
204+ # $3 (previous word) that are specified to the completion function by Bash.
205+ # When `-s` is specified, instead of variable `split`, the new interface sets
206+ # variable `was_split` to the value "set"/"" when the split happened/not
207+ # happened.
208+ _init_completion ()
209+ {
210+ local was_split
211+ _comp_initialize " $@ "
212+ local rc=$?
213+
214+ # When -s is specified, convert "split={set,}" to "split={true,false}"
215+ local flag OPTIND=1 OPTARG=" " OPTERR=0
216+ while getopts " n:e:o:i:s" flag " $@ " ; do
217+ case $flag in
218+ [neoi]) ;;
219+ s)
220+ if [[ $was_split ]]; then
221+ split=true
222+ else
223+ split=false
224+ fi
225+ break
226+ ;;
227+ esac
228+ done
229+
230+ return " $rc "
231+ }
232+
181233# @deprecated Use the variable `_comp_backup_glob` instead. This is the
182234# backward-compatibility name.
183235# shellcheck disable=SC2154 # defined in the main "bash_completion"
0 commit comments