From 237f63820a5f3d9ec88ada7630b01057eba7c205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABlan?= Date: Tue, 2 Jul 2024 16:02:17 +0200 Subject: [PATCH] =?UTF-8?q?feat(=5Fcomp=5Fcompgen=5Ffiledir,=5Fcomp=5Fcomp?= =?UTF-8?q?gen=5Ffiledir=5Fxspec):=20don=E2=80=99t=20suggest=20.=20and=20.?= =?UTF-8?q?.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bash_completion | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/bash_completion b/bash_completion index bf42e00885b..f06dca43ea4 100644 --- a/bash_completion +++ b/bash_completion @@ -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' @@ -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[@]}"' }