Blame SOURCES/bash-4.3-dircomp-append-slash.patch

ff19ae
diff --git a/bashline.c b/bashline.c
ff19ae
--- a/bashline.c
ff19ae
+++ b/bashline.c
ff19ae
@@ -117,6 +117,7 @@ static char *restore_tilde __P((char *, char *));
ff19ae
 
ff19ae
 static char *bash_filename_rewrite_hook __P((char *, int));
ff19ae
 static void bash_directory_expansion __P((char **));
ff19ae
+static int bash_filename_stat_hook __P((char **));
ff19ae
 static int bash_directory_completion_hook __P((char **));
ff19ae
 static int filename_completion_ignore __P((char **));
ff19ae
 static int bash_push_line __P((void));
ff19ae
@@ -1414,7 +1415,7 @@ bash_default_completion (text, start, end, qc, compflags)
ff19ae
      const char *text;
ff19ae
      int start, end, qc, compflags;
ff19ae
 {
ff19ae
-  char **matches;
ff19ae
+  char **matches, *t;
ff19ae
 
ff19ae
   matches = (char **)NULL;
ff19ae
 
ff19ae
@@ -1424,7 +1425,19 @@ bash_default_completion (text, start, end, qc, compflags)
ff19ae
       if (qc != '\'' && text[1] == '(') /* ) */
ff19ae
 	matches = rl_completion_matches (text, command_subst_completion_function);
ff19ae
       else
ff19ae
-	matches = rl_completion_matches (text, variable_completion_function);
ff19ae
+	{
ff19ae
+	  matches = rl_completion_matches (text, variable_completion_function);
ff19ae
+	  if (matches && matches[0] && matches[1] == 0)
ff19ae
+	    {
ff19ae
+	      t = savestring (matches[0]);
ff19ae
+	      bash_filename_stat_hook (&t);
ff19ae
+	      /* doesn't use test_for_directory because that performs tilde
ff19ae
+		 expansion */
ff19ae
+	      if (file_isdir (t))
ff19ae
+		rl_completion_append_character = '/';
ff19ae
+	      free (t);
ff19ae
+	    }
ff19ae
+	}
ff19ae
     }
ff19ae
 
ff19ae
   /* If the word starts in `~', and there is no slash in the word, then
ff19ae
@@ -2763,6 +2776,57 @@ restore_directory_hook (hookf)
ff19ae
     rl_directory_rewrite_hook = hookf;
ff19ae
 }
ff19ae
 
ff19ae
+static int
ff19ae
+bash_filename_stat_hook (dirname)
ff19ae
+     char **dirname;
ff19ae
+{
ff19ae
+  char *local_dirname, *new_dirname, *t;
ff19ae
+  int should_expand_dirname, return_value;
ff19ae
+  WORD_LIST *wl;
ff19ae
+  struct stat sb;
ff19ae
+
ff19ae
+  local_dirname = *dirname;
ff19ae
+  should_expand_dirname = return_value = 0;
ff19ae
+  if (t = mbschr (local_dirname, '$'))
ff19ae
+    should_expand_dirname = '$';
ff19ae
+  else if (t = mbschr (local_dirname, '`'))	/* XXX */
ff19ae
+    should_expand_dirname = '`';
ff19ae
+
ff19ae
+#if defined (HAVE_LSTAT)
ff19ae
+  if (should_expand_dirname && lstat (local_dirname, &sb) == 0)
ff19ae
+#else
ff19ae
+  if (should_expand_dirname && stat (local_dirname, &sb) == 0)
ff19ae
+#endif
ff19ae
+    should_expand_dirname = 0;
ff19ae
+  
ff19ae
+  if (should_expand_dirname)  
ff19ae
+    {
ff19ae
+      new_dirname = savestring (local_dirname);
ff19ae
+      wl = expand_prompt_string (new_dirname, 0, W_NOCOMSUB|W_NOPROCSUB);    /* does the right thing */ 
ff19ae
+      if (wl)
ff19ae
+	{
ff19ae
+	  free (new_dirname);
ff19ae
+	  new_dirname = string_list (wl);
ff19ae
+	  /* Tell the completer we actually expanded something and change
ff19ae
+	     *dirname only if we expanded to something non-null -- stat
ff19ae
+	     behaves unpredictably when passed null or empty strings */
ff19ae
+	  if (new_dirname && *new_dirname)
ff19ae
+	    {
ff19ae
+          free (local_dirname); /* XXX */
ff19ae
+	      local_dirname = *dirname = new_dirname; 
ff19ae
+	      return_value = STREQ (local_dirname, *dirname) == 0;
ff19ae
+	    }
ff19ae
+      else
ff19ae
+	      free (new_dirname);
ff19ae
+	  dispose_words (wl);
ff19ae
+	}
ff19ae
+      else
ff19ae
+	free (new_dirname);
ff19ae
+    }	
ff19ae
+
ff19ae
+  return (return_value);
ff19ae
+}
ff19ae
+
ff19ae
 /* Handle symbolic link references and other directory name
ff19ae
    expansions while hacking completion.  This should return 1 if it modifies
ff19ae
    the DIRNAME argument, 0 otherwise.  It should make sure not to modify