I find it a little unpleasant that cd echoes the new working directory
when CDPATH is used to locate the new directory (I already have the
working directory in my prompt).  I understand that this is behavior
is mandated by POSIX but I wonder if we could have an option that
disables this.

Maybe if the `cd' builtin had an option, say `-q', that would cause it
to be quit if CDPATH is used.  Then, I could simply

alias cd='cd -q'

and put a stop to this.  I have attached a proposed patch, any thoughts?

Thanks,
-------
Elliott Forney                        E-Mail: id...@cs.colostate.edu
Graduate Student                      Phone:  1.402.215.7440
Computer Science Department           Web:    http://www.cs.colostate.edu/~idfah
Colorado State University
diff -u builtins/cd.def.orig builtins/cd.def
--- builtins/cd.def.orig  2014-01-20 16:52:02.000000000 -0700
+++ builtins/cd.def 2014-01-20 16:37:17.000000000 -0700
@@ -92,6 +92,8 @@
  links
     -e if the -P option is supplied, and the current working directory
  cannot be determined successfully, exit with a non-zero status
+    -q  prevent the working directory from being echoed when the
+  CDPATH variable is used to locate DIR
 
 The default is to follow symbolic links, as if `-L' were specified.
 
@@ -187,7 +189,7 @@
      WORD_LIST *list;
 {
   char *dirname, *cdpath, *path, *temp;
-  int path_index, no_symlinks, opt, lflag;
+  int path_index, no_symlinks, opt, lflag, qflag;
 
 #if defined (RESTRICTED_SHELL)
   if (restricted)
@@ -198,9 +200,10 @@
 #endif /* RESTRICTED_SHELL */
 
   eflag = 0;
+  qflag = 0;
   no_symlinks = no_symbolic_links;
   reset_internal_getopt ();
-  while ((opt = internal_getopt (list, "LP")) != -1)
+  while ((opt = internal_getopt (list, "LPq")) != -1)
     {
       switch (opt)
  {
@@ -213,6 +216,9 @@
  case 'e':
    eflag = 1;
    break;
+ case 'q':
+   qflag = 1;
+   break;
  default:
    builtin_usage ();
    return (EXECUTION_FAILURE);
@@ -274,7 +280,7 @@
     is used to find the directory to change to, the new
     directory name is echoed to stdout, whether or not
     the shell is interactive. */
-       if (opt && (path = no_symlinks ? temp : the_current_working_directory))
+       if (opt && !qflag && (path = no_symlinks ? temp : the_current_working_directory))
    printf ("%s\n", path);
 
        free (temp);

Reply via email to