@@ -791,6 +791,8 @@ _comp_compgen__call_generator()
791791 local _comp_compgen__append=$_append
792792 local _comp_compgen__var=$_var
793793 local _comp_compgen__cur=$_cur cur=$_cur
794+ local _comp_compgen__dir=$_dir
795+ local _comp_compgen__prefix=$_prefix
794796 if [[ $_prefix ]]; then
795797 local -a tmp=()
796798 local _comp_compgen__var=tmp
@@ -1287,10 +1289,7 @@ _comp_quote_compgen()
12871289# OPTIONS
12881290# -d Complete only on directories
12891291# -f Perform `compopt -o filenames` modifications manually. This
1290- # suffixes a slash to a directory name. This can be combined with
1291- # the `-C dir` option to `_comp_compgen`, where the generated
1292- # filenames do not exist in the current working directory and Bash
1293- # fails to properly detect the filenames.
1292+ # suffixes a slash to a directory name.
12941293# @return 0 if at least one completion is generated, or 1 otherwise.
12951294#
12961295# @since 2.12
@@ -1300,6 +1299,19 @@ _comp_compgen_filedir()
13001299
13011300 local -a toks
13021301 local _dir=" " _filenames=" "
1302+ if [[ ${_comp_compgen__dir-} || ${_comp_compgen__prefix-} ]]; then
1303+ # When "-C <dir>" or "-P <prefix>" is specified, the working directory
1304+ # does not contain the generated candidates as filenames. In the case
1305+ # of "-C <dir>", the generated filenames are located in the directory
1306+ # "<dir>" but not in the working directory. In the case of "-P
1307+ # <prefix>", candidates have the form "<prefix><filename>". In those
1308+ # cases, Bash fails to recognize the generated candidates to be
1309+ # filenames, and Bash does not adjust these as filenames. We
1310+ # automatically detect such cases and modify the generated filenames as
1311+ # if the option "-f" is passed.
1312+ _filenames=set
1313+ fi
1314+
13031315 local OPTIND=1 OPTARG=" " OPTERR=0 _opt
13041316 while getopts " :df" _opt " $@ " ; do
13051317 case $_opt in
0 commit comments