Package: bash
Version: 3.0-13
Severity: wishlist
Tags: patch

Hi, as per discussion on -devel, it'd be nice if you could set $DOTPATH to tell . to search for shell snippets that don't need to be on the PATH.

ie,

$ cd
$ mkdir snippets
$ echo 'f () { echo hello, world; }' > snippets/hello.sh
$ DOTPATH=~/snippets
$ . hello.sh
$ f
hello, world

See http://lists.debian.org/debian-devel/2005/01/msg01907.html and the rest of the thread for the discussion.

Sample patch follows. Sorry about any wrapping problems. :-/

diff -urb bash-3.0/bash/builtins/source.def bash-3.0-aj/bash/builtins/source.def
--- bash-3.0/bash/builtins/source.def 2003-12-20 10:03:06.000000000 +1000
+++ bash-3.0-aj/bash/builtins/source.def 2005-02-01 13:53:03.234194528 +1000
@@ -72,6 +72,9 @@
extern int restricted;
#endif


+/* If non-zero, `.' uses $DOTPATH to look up the script to be sourced. */
+int source_uses_dotpath = 1;
+
 /* If non-zero, `.' uses $PATH to look up the script to be sourced. */
 int source_uses_path = 1;

@@ -128,8 +131,15 @@
 #endif

   filename = (char *)NULL;
+  if (source_uses_dotpath)
+    {
+      filename = find_path_file_in (list->word->word, "DOTPATH");
+    }
+  if (filename == 0)
+    {
   if (source_uses_path)
     filename = find_path_file (list->word->word);
+    }
   if (filename == 0)
     {
       if (source_searches_cwd == 0)
diff -urb bash-3.0/bash/findcmd.c bash-3.0-aj/bash/findcmd.c
--- bash-3.0/bash/findcmd.c     2003-09-13 04:50:45.000000000 +1000
+++ bash-3.0-aj/bash/findcmd.c  2005-02-01 13:53:33.235633616 +1000
@@ -47,8 +47,8 @@
 extern int posixly_correct;

/* Static functions defined and used in this file. */
-static char *_find_user_command_internal __P((const char *, int));
-static char *find_user_command_internal __P((const char *, int));
+static char *_find_user_command_internal __P((const char *, int, const char *));
+static char *find_user_command_internal __P((const char *, int, const char *));
static char *find_user_command_in_path __P((const char *, char *, int));
static char *find_in_path_element __P((const char *, char *, int, int, struct stat *));
static char *find_absolute_program __P((const char *, int));
@@ -174,7 +174,7 @@
find_user_command (name)
const char *name;
{
- return (find_user_command_internal (name, FS_EXEC_PREFERRED|FS_NODIRS));
+ return (find_user_command_internal (name, FS_EXEC_PREFERRED|FS_NODIRS, "PATH"));
}


 /* Locate the file referenced by NAME, searching along the contents
@@ -182,23 +182,32 @@
    pathname to the file, or NULL if the file couldn't be found.  This
    returns the first file found. */
 char *
+find_path_file_in (name, pathvar)
+     const char *name;
+     const char *pathvar;
+{
+  return (find_user_command_internal (name, FS_EXISTS, pathvar));
+}
+
+char *
 find_path_file (name)
      const char *name;
 {
-  return (find_user_command_internal (name, FS_EXISTS));
+  return (find_user_command_internal (name, FS_EXISTS, "PATH"));
 }

 static char *
-_find_user_command_internal (name, flags)
+_find_user_command_internal (name, flags, pathvar)
      const char *name;
      int flags;
+     const char *pathvar;
 {
   char *path_list, *cmd;
   SHELL_VAR *var;

/* Search for the value of PATH in both the temporary environments and
in the regular list of variables. */
- if (var = find_variable_internal ("PATH", 1)) /* XXX could be array? */
+ if (var = find_variable_internal (pathvar, 1)) /* XXX could be array? */
path_list = value_cell (var);
else
path_list = (char *)NULL;
@@ -212,9 +221,10 @@
}


 static char *
-find_user_command_internal (name, flags)
+find_user_command_internal (name, flags, pathvar)
      const char *name;
      int flags;
+     const char *pathvar;
 {
 #ifdef __WIN32__
   char *res, *dotexe;
@@ -222,13 +232,13 @@
   dotexe = (char *)xmalloc (strlen (name) + 5);
   strcpy (dotexe, name);
   strcat (dotexe, ".exe");
-  res = _find_user_command_internal (dotexe, flags);
+  res = _find_user_command_internal (dotexe, flags, pathvar);
   free (dotexe);
   if (res == 0)
-    res = _find_user_command_internal (name, flags);
+    res = _find_user_command_internal (name, flags, pathvar);
   return res;
 #else
-  return (_find_user_command_internal (name, flags));
+  return (_find_user_command_internal (name, flags, pathvar));
 #endif
 }

diff -urb bash-3.0/bash/findcmd.h bash-3.0-aj/bash/findcmd.h
--- bash-3.0/bash/findcmd.h     2001-09-14 05:24:53.000000000 +1000
+++ bash-3.0-aj/bash/findcmd.h  2005-02-01 13:48:30.487658304 +1000
@@ -29,6 +29,7 @@
 extern int executable_or_directory __P((const char *));
 extern char *find_user_command __P((const char *));
 extern char *find_path_file __P((const char *));
+extern char *find_path_file_in __P((const char *, const char *));
 extern char *search_for_command __P((const char *));
 extern char *user_command_matches __P((const char *, int, int));



Cheers,
aj


-- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]



Reply via email to