From 1df99a6231a6311baf8132e53a1f8bfff072af35 Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Mon, 2 Jan 2023 18:34:28 -0800 Subject: [PATCH] Fix bashrc .complete completion behavior This commit updates the completion function for the .functions (`..`, `.2`, etc.) to behave as much like tab completion for `cd` as possible. This means it has better listing for possible results when multiple options are available, properly handles completed and nested directories (!!) and is much more thoroughly documented so it's not such a dense cluster of bash magic. --- src/.bashrc | 74 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 11 deletions(-) diff --git a/src/.bashrc b/src/.bashrc index e3f4f4f..e031081 100755 --- a/src/.bashrc +++ b/src/.bashrc @@ -385,7 +385,15 @@ function _bashrc_.complete { return 1 fi - local parent_depth path_array i parent_path word_list matched_word + COMPREPLY=() + + # don't try to find matches if the search term starts with '/' + if [[ "${word:0:1}" == '/' ]]; then + return + fi + + local parent_depth path_array i IGNORE_CASE search_path search_term \ + search_word matched_words matched_word parent_depth="${cmd//.}" if [ -z "$parent_depth" ]; then parent_depth=1 @@ -394,18 +402,62 @@ function _bashrc_.complete { for (( i=0; i