root@homer.UUCP (07/31/86)
this is an alias i've been using for a long time that i find very
handy. just thought i'd share it. it will allow you to specify a
directory to cd to by naming its intitals only. for example, to cd to
the directory "/usr/fred/memos/archives/mary", type "c ufmam".
if the initials are not unique (more than one directory has those
initials), an error will result. if sucessful, the pathname that the
initials expanded to will be echoed, and you will be cd'd.
enjoy.
alias c 'set d=`echo \!^* | sed "s/./\/&*/g"`; cd $d || echo $d'
-----
marc brumlik
...trsvax!hal6000!unify1!\
>homer!marc
...ihnp4!sys1!/
rlk@mit-trillian.MIT.EDU (Robert L Krawitz) (08/14/86)
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
mcintosh@moncskermit.oz (Glenn McIntosh) (08/16/86)
In article <1004@mit-trillian.MIT.EDU>, rlk@mit-trillian.MIT.EDU (Robert L Krawitz) writes: > alias ncd 'set d=`echo \!^* | sed "s/./\/&*/g"`; set d = `dirp $d`; cd $d || echo $d' > [and includes C program "dirp"] Another method to cause the alias to select only directories and not other files is to add a "/" character in the appropriate place in the alias (I've only tried this on a BSD system) i.e., alias c 'set d=`echo \!^* | sed "s/./\/&*/g"`/; cd $d || echo $d' Tirian --- -- Glenn McIntosh UUCP : {pesnta,decvax}!mulga!moncsbruce.oz!mcintosh : {seismo,hplabs,mcvax,ukc,nttlab}!munnari!moncsbruce.oz!mcintosh ARPA : munnari!moncsbruce.oz!mcintosh@seismo.arpa CSNET : mcintosh@moncsbruce.oz Computer Science Dept., Monash University, Clayton, Victoria 3168, Australia