Skip to content

Commit

Permalink
feat(_comp_compgen_filedir,_comp_compgen_filedir_xspec): don’t sugges…
Browse files Browse the repository at this point in the history
…t . and ..
  • Loading branch information
Maelan committed Jul 2, 2024
1 parent e209afb commit 56e38a9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,17 @@ _comp_compgen_filedir()
compopt -o filenames 2>/dev/null
fi

# Remove . and .. (as well as */. and */..) from suggestions,
# unless .. or */.. was typed explicitly by the user
# (for users who use tab-completion to append a slash after '..')
if [[ "${cur}" != @(..|*/..) ]]; then
local i
for i in "${!toks[@]}" ; do
[[ "${toks[$i]}" == @(.|..|*/.|*/..) ]] && \
unset -v "toks[$i]"
done
fi

# Note: bash < 4.4 has a bug that all the elements are connected with
# ${v+"${a[@]}"} when IFS does not contain whitespace.
local IFS=$' \t\n'
Expand Down Expand Up @@ -3042,6 +3053,17 @@ _comp_compgen_filedir_xspec()
((${#toks[@]})) || return 1
# Remove . and .. (as well as */. and */..) from suggestions,
# unless .. or */.. was typed explicitly by the user
# (for users who use tab-completion to append a slash after '..')
if [[ "${cur}" != @(..|*/..) ]]; then
local i
for i in "${!toks[@]}" ; do
[[ "${toks[$i]}" == @(.|..|*/.|*/..) ]] && \
unset -v "toks[$i]"
done
fi
compopt -o filenames
_comp_compgen -RU toks -- -W '"${toks[@]}"'
}
Expand Down

0 comments on commit 56e38a9

Please sign in to comment.