a useful alias

Robert L Krawitz rlk at mit-trillian.MIT.EDU
Thu Aug 14 11:09:34 AEST 1986


The only problem with that alias is that it doesn't discriminate
between directories and other files.  A slight modification, with the
help of a small C program, fixes that:

alias	ncd	'set d=`echo \!^* | sed "s/./\/&*/g"`; set d = `dirp $d`; cd $d || echo $d'

/* dirp -- echo arguments that are directories */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

struct stat stats;

main(argc,argv)
     int argc;
     char **argv;
{
  char *file;
  argc--;
  argv++;
  while (argc > 0)
    {
      file = *argv;
      stat(file, &stats);
      if (((stats.st_mode) & S_IFMT) == S_IFDIR) printf ("%s\n", file);
      argc--;
      argv++;
    }
}
-- 
Robert^Z



More information about the Comp.sources.unix mailing list