From c0e2c0977e2ffe06a8643d1e042047dba15d850e Mon Sep 17 00:00:00 2001 From: Chet Ramey Date: Tue, 13 Mar 2012 16:42:16 -0400 Subject: [PATCH] Bash-4.2 direxpand-relpath patch to not expand relative pathnames --- bashline.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/bashline.c b/bashline.c index d42f3f03a..3cbb18fd8 100644 --- a/bashline.c +++ b/bashline.c @@ -248,6 +248,7 @@ int dircomplete_spelling = 0; /* Expand directory names during word/filename completion. */ int dircomplete_expand = 0; +int dircomplete_expand_relpath = 0; static char *bash_completer_word_break_characters = " \t\n\"'@><=;|&(:"; static char *bash_nohostname_word_break_characters = " \t\n\"'><=;|&(:"; @@ -2855,11 +2856,31 @@ bash_directory_completion_hook (dirname) local_dirname = *dirname = new_dirname; } + /* no_symbolic_links == 0 -> use (default) logical view of the file system. + local_dirname[0] == '.' && local_dirname[1] == '/' means files in the + current directory (./). + local_dirname[0] == '.' && local_dirname[1] == 0 means relative pathnames + in the current directory (e.g., lib/sh). + XXX - should we do spelling correction on these? */ + + /* This is test as it was in bash-4.2: skip relative pathnames in current + directory. Change test to + (local_dirname[0] != '.' || (local_dirname[1] && local_dirname[1] != '/')) + if we want to skip paths beginning with ./ also. */ if (no_symbolic_links == 0 && (local_dirname[0] != '.' || local_dirname[1])) { char *temp1, *temp2; int len1, len2; + /* If we have a relative path + (local_dirname[0] != '/' && local_dirname[0] != '.') + that is canonical after appending it to the current directory, then + temp1 = temp2+'/' + That is, + strcmp (temp1, temp2) == 0 + after adding a slash to temp2 below. It should be safe to not + change those. + */ t = get_working_directory ("symlink-hook"); temp1 = make_absolute (local_dirname, t); free (t); @@ -2894,7 +2915,15 @@ bash_directory_completion_hook (dirname) temp2[len2 + 1] = '\0'; } } - return_value |= STREQ (local_dirname, temp2) == 0; + + /* dircomplete_expand_relpath == 0 means we want to leave relative + pathnames that are unchanged by canonicalization alone. + *local_dirname != '/' && *local_dirname != '.' == relative pathname + (consistent with general.c:absolute_pathname()) + temp1 == temp2 (after appending a slash to temp2) means the pathname + is not changed by canonicalization as described above. */ + if (dircomplete_expand_relpath || ((local_dirname[0] != '/' && local_dirname[0] != '.') && STREQ (temp1, temp2) == 0)) + return_value |= STREQ (local_dirname, temp2) == 0; free (local_dirname); *dirname = temp2; free (temp1); -- 2.47.2