Anonymous avatar Anonymous committed 74d7ae4

Initial revision

Comments (0)

Files changed (8)

+Installing gd
+=============
+
+Note that this describes system level installation. Each user will
+have to make a shell-alias or -function to use gd. Please see the
+manual pages for how to do that.
+
+Installing gd is quite simple, just copy `gdprog' to some
+bin-directory, and `gd.1' and `gdprog.1' to a matching
+man/man1-directory.
+
+You may also execute `make install'. This will install `gdprog' in
+/usr/local/bin, and `gd.1' and `gdprog.1' in /usr/local/man/man1.
+
+# $Id$
+DIST		= gd
+# Remeber to update version in the perl-file too!
+VERMAJ		= 1
+VERMIN		= 2
+VERSION		= $(VERMAJ).$(VERMIN)
+
+BASEDIR		= /usr/local
+BINDIR		= $(BASEDIR)/bin
+MANDIR		= $(BASEDIR)/man/man1
+INSTALLDATA	= install -m 644
+INSTALLBIN	= install -m 755
+
+all:
+	@echo Type \`make install\' to install $(DIST) in $(BASEDIR)
+
+install:
+	$(INSTALLBIN) gdprog $(BINDIR)
+	$(INSTALLDATA) gdprog.1 gd.1 $(MANDIR)
+
+clean:
+	rm -f *~
+
+veryclean: clean
+	rm -f $(DIST)-$(VERSION).tar.gz $(DIST)-$(VERSION).lsm
+
+chmod:
+	chmod a+r *
+	chmod a+x gdprog
+
+# To let the author make a distribution. The rest of the Makefile
+# should be used by the author only.
+LSMFILE		= $(DIST)-$(VERSION).lsm
+DISTDIR		= $(DIST)-$(VERSION)
+DISTFILE	= $(DIST)-$(VERSION).tar.gz
+DISTFILES	= README INSTALL $(LSMFILE) \
+		  Makefile gdprog gd.1 gdprog.1 gd.ver
+
+$(LSMFILE): FORCE
+	VER=$(VERSION); \
+	DATE=`date "+%d%b%y"|tr '[a-z]' '[A-Z]'`; \
+	sed -e "s/VER/$$VER/g;s/DATE/$$DATE/g" $(DIST).lsm.in > $(LSMFILE)
+
+FORCE:
+
+# Warning: distclean removes the lsm-file, which can not be
+# regenerated without the lsm.in-file, which is not part of the package.
+distclean: veryclean
+	rm -f $(LSMFILE)
+
+dist: $(LSMFILE) chmod
+	mkdir $(DISTDIR)
+	chmod a+rx $(DISTDIR)
+	ln $(DISTFILES) $(DISTDIR)
+	tar -cvzf $(DISTFILE) $(DISTDIR)
+	chmod a+r $(DISTFILE)
+	rm -rf $(DISTDIR)
+gd - Goto Directory
+===================
+
+gd will let you change to a subdirectory within your personal
+home-directory tree just by specifying parts of the directory name. It
+is inspired by old versions (with no tree-visualizer) of Norton Change
+Directory for M$-DOS. To work as expected, the user will have to
+install a shell-alias or -function. Please see the manual pages for
+end user installation.
+
+The program is written in perl by
+
+	Sverre H. Huseby
+	Maridalsvn. 122, leil. 101
+	N-0461 Oslo
+	Norway
+
+	sverrehu@ifi.uio.no
+
+You can use and copy this for free. If you decide to use it, please do
+me three small favours:
+
+	1. Tell me! (E-mail, postcard, letter, whatever. If you wish
+	   to give me something, please send a bottle of your
+	   favourite beer (making this BeerWare))
+	2. Let your friends and favourite download site have a copy!
+	   (with all files intact, please..)
+	3. Report any bugs you find!
+
+Begin3
+Title:		gd - Goto Directory
+Version:	1.2
+Entered-date:	11AUG95
+Description:	gd makes it possible to change to another directory without
+		entering more of it's name than the start of the last
+		path-element. 
+Keywords:	directory
+Author: 	sverrehu@ifi.uio.no (Sverre H. Huseby)
+Primary-site:	sunsite.unc.edu /pub/Linux/utils/shell
+		gd-1.2.tar.gz
+Platforms:	Requires perl. Works with perl5, and probably perl4 too.
+Copying-policy:	BeerWare: If you have the time and money, send me a bottle
+		of your favourite beer. If not, just send me a mail or
+		something. Copy and use as you wish; just leave the
+		author's name where you find it.
+End
+.TH GD 1
+.SH NAME
+gd \- alias: quickly change to another directory
+.SH SYNOPSIS
+.ll +8
+.B gd
+.RB [ " \-r "
+]
+.RB [ " \-\-rebuild "
+]
+[
+.I "directory"
+]
+.ll -8
+.SH DESCRIPTION
+.I gd
+makes it possible to move to another directory without entering more
+of it's name than the start of the last path-element.
+It keeps a file containing the directory structure of and in the
+home directory of each user.
+
+Note:
+.I gd
+is supposed to be a shell-alias or -function. See
+gdprog(1) for installation instructions.
+
+The program will first check if a normal chdir to the given
+directory will work. If not, it searches the (home-) directory
+tree top to bottom, left to right (in an alphabetic manner) for
+a match. The search starts with the directory after the current,
+and wraps around to the start when the end is reached.
+
+To save some typing, a match is defined to be a directory who's
+`last name' starts with the name given.
+
+Scanning the directory structure takes some time, so instead of
+doing that,
+.I gd
+keeps the structure in a file. This file needs to be updated
+whenever directories are added or removed. If, whenever
+.I gd
+is started, the current directory
+(below home) is not in the file, a rescan will be performed
+automatically. However, if the directory structure is changed without
+.IR gd 's
+knowing, you may have to rebuild the file using the \-r option.
+This is the case if
+.I gd
+is unable to find an existing directory, or
+if it tries to move to a location that no longer exists.
+.SH OPTIONS
+.TP
+.B \-r, \-\-rebuild
+Rebuild the directory structure file. Use this when
+.I gd
+complains about unknown directories, or to update the file
+when directories have been added or removed.
+.SH FILES
+The directory structure is stored in .gdinfo in the user's
+home-directory.
+.SH ENVIRONMENT
+The environment variable
+.B HOME
+is used to determine the homedirectory of the current user.
+.SH SEE ALSO
+gdprog(1)
+.SH HISTORY
+.I gd
+appeared in 1990 as an MS-DOS program (by the same author).
+.SH AUTHOR
+This perl-program was written from scratch in 1994 by Sverre H. Huseby,
+Norway (sverrehu@ifi.uio.no)
+1.2, 95/8/10
+  * Created README, INSTALL and .lsm -files, and updated Makefile to
+    create a distribution.
+  * Removed -w from perl-line, since perl complained about uninitialized
+    variables when checking empty ARGV.
+  * Renamed this file from gdprog.ver to gd.ver
+
+0.24, 95/6/4
+  * Fixed a bug: The program wouldn't change to directories containing
+    a space in the name. Thanks to Alexey Marinichev <lyosha@tdb.uu.se>
+    for spotting this bug.
+
+0.23, 95/2/16
+  * No longer aborts if unable to read a directory, but rather
+    gives a warning.
+
+0.22, 95/2/12
+  * Hopefully removed bug that caused looping when certain unknown
+    directories were given.
+
+0.2, 94/10/23
+  * No longer follows directories that are symlinks, since
+    these may cause cyclic references.
+
+0.1, 94/9/22
+#! /usr/local/bin/perl
+# $Id$
+$prog_ver = "v1.2";       # Remember to update version in Makefile too!
+$prog_date = "10/8/95";
+#############################################################################
+### gdprog/gd by Sverre H. Huseby, Norway.
+###
+### Enables quickly changing to a directory below home by only giving
+### parts of the `basename'. For instance: "gd sun" may change to
+### ~/bin/sun4
+###
+### Configuration section ###################################################
+
+$gd = "gd";
+$gdprog = "gdprog";
+$gdfilebase = ".gdinfo";
+
+### End of configuration section ############################################
+
+$home = $ENV{'HOME'};
+$gdfile = "$home/$gdfilebase";
+
+$force_rebuild = 0;
+$target_dir = "";
+
+$installed = 0;
+@dirs = ();
+
+sub collectDirs {
+    local($curr) = @_;
+    local(@glob, @loc, $name, $q, $ndirs);
+    @glob = ();
+    $q = $ndirs = 0;
+    while ($q <= $ndirs) {
+	@loc = ();
+	if (opendir(D, $curr)) {
+	    while ($name = readdir(D)) {
+		$name = "$curr/$name";
+		# Don't follow symlinked directories - may be cyclic.
+		if (! -l $name && -d _) {
+		    next if $name =~ m#/\.\.?$#;
+		    push(@loc, $name);
+		    ++$ndirs;
+		}
+	    }
+	    close(D);
+	    push(@glob, sort @loc);
+	} else {
+	    print "$gd: warning: unable to open dir $curr\n";
+	}
+	$curr = $glob[$q++];
+    }
+    @glob;
+}
+
+sub buildDirTree {
+    local($q);
+    print STDERR "Building directory tree, storing in ~/$gdfilebase\n";
+    @dirs = &collectDirs($home);
+    open(F, ">$gdfile") || die "$gd: unable to write to $gdfile\n";
+    for ($q = 0; $q < @dirs; $q++) {
+	$_ = $dirs[$q];
+	s#^$home/##;
+	print F "$_\n";
+    }
+    close(F);
+}
+
+sub loadDirTree {
+    @dirs = ();
+    if (!-f $gdfile) {
+	&buildDirTree;
+    } else {
+	open(F, $gdfile) || die "$gd: unable to read $gdfile\n";
+	while (<F>) {
+	    chop;
+	    push(@dirs, "$home/$_");
+	}
+	close(F);
+    }
+}
+
+sub fullyMatchDir {
+    local($dir) = @_;
+    local($q);
+    for ($q = 0; $q < @dirs; $q++) {
+	last if $dirs[$q] =~ m#^$dir$#;
+    }
+    if ($q == @dirs) {
+	-1;
+    } else {
+	$q;
+    }
+}
+
+sub partiallyMatchDir {
+    local($dir, $startidx) = @_;
+    local($q, $cnt, $totcnt);
+    $totcnt = @dirs + 0;
+    for ($q = $startidx, $cnt = 0; $cnt < $totcnt; $q++, $cnt++) {
+	$q = 0 if $q >= $totcnt;
+	last if $dirs[$q] =~ m#/$dir[^/]*$#;
+    }
+    if ($q == $startidx && $cnt) {
+	-1;
+    } else {
+	$q;
+    }
+}
+
+sub gotoDirectory {
+    local($currdir, $curridx, $short_dir, $idx);
+    $target_dir =~ s#(.*[^/]*)/$#$1#;
+    if ($force_rebuild) {
+	&buildDirTree;
+    } else {
+	&loadDirTree;
+    }
+    $currdir = `pwd`;
+    $currdir =~ s#/?\n+##;
+    $curridx = -1;
+    if ($currdir =~ m#^$home/.+#) {
+	if (($curridx = &fullyMatchDir($currdir)) == -1 && !$force_rebuild) {
+	    &buildDirTree;
+	    if (($curridx = &fullyMatchDir($currdir)) == -1) {
+		$curridx = -1;
+	    }
+	}
+    }
+    if (!chdir($target_dir)) {
+	if (($idx = &partiallyMatchDir($target_dir, $curridx + 1)) == -1) {
+	    die "$gd: unknown directory: $target_dir\n";
+	}
+	$target_dir = $dirs[$idx];
+	chdir($target_dir) || die "$gd: unable to chdir to $target_dir\n";
+    }
+    $short_dir = $target_dir;
+    $short_dir =~ s#^$home#~#;
+    print STDERR "--> $short_dir\n";
+    print "$target_dir\n";
+    exit 0;
+}
+
+sub installBashFunction {
+    print "function gd() { GD_DIR=`$0 gd \$*` && cd \"\$GD_DIR\" }\n";
+    exit 0;
+}
+
+sub installTcshAlias {
+    print "alias gd 'set gd_dir=`$0 gd \\!*` && cd \"\$gd_dir\"'\n";
+    exit 0;
+}
+
+sub showUsage {
+    if ($installed) {
+#/*
+        print STDERR <<EOT;
+	
+$gd $prog_ver $prog_date - Sverre H. Huseby, Norway
+
+Goto Directory. Maintains a file named $gdfilebase in the home
+directory. This file contains the treestructure of the home, so
+that $gd can quickly find a directory.
+
+usage: $gd [options] directory
+
+       Options:
+         -r, --rebuild
+             Update the treestructure file. Used when changes has been
+	     made to the directories.
+
+       The directory name need not be fully specified.
+
+       Note that $gd will try a `normal' chdir before searching the
+       file for names.
+       
+EOT
+#*/
+    } else {
+#/*
+        print STDERR <<EOT;
+	
+$gdprog $prog_ver $prog_date - Sverre H. Huseby, Norway
+
+This program should not be called directly, but rather through
+a shell-alias or -function named gd. If you use any of the shells
+the program knows about, use the following to install the alias:
+
+       eval `$gdprog [install-option]`
+      
+       install-option is one of:
+       -ib, --install-bash
+               Print installation command for bash
+       -it, --install-tcsh
+               Print installation command for tcsh
+
+To install manually, create an alias $gd that calls $gdprog with
+gd as the first parameter, followed by the parameters to $gd.
+The output should be stored in a shell-variable, and passed to
+cd if $gdprog exited with success.
+
+EOT
+#*/
+    }
+    exit 1;
+}
+
+sub getOptions {
+    local($a, $cnt, $id);
+    if ($ARGV[0] eq "gd") {
+	$installed = 1;
+	$id = $gd;
+	shift @ARGV;
+    } else {
+	$id = $gdprog;
+    }
+    &showUsage if !@ARGV;
+    $cnt = 0;
+    while (@ARGV) {
+	$a = shift @ARGV;
+        if ($a =~ m#^-#) {
+	    if ($a eq "-h" || $a eq "--help") {
+	        &showUsage;
+	    } elsif (!$installed && ($a eq "-ib" || $a eq "--install-bash")) {
+	        &installBashFunction;
+	    } elsif (!$installed && ($a eq "-it" || $a eq "--install-tcsh")) {
+	        &installTcshAlias;
+	    } elsif ($installed && ($a eq "-r" || $a eq "--rebuild")) {
+	        $force_rebuild = 1;
+	    } else {
+	        die "$id: unknown option $a\n";
+	    }
+        } elsif ($installed) {
+            if ($cnt == 0) {
+                $target_dir = $a;
+                ++$cnt;
+            } else {
+                die "$gd: more than one directory given\n";
+            }
+        } else {
+	    die "$gdprog: unknown argument $a\n";
+	}
+    }
+}
+
+### main() ############################################################
+
+&getOptions;
+if (length($target_dir) == 0) {
+    if ($force_rebuild) {
+	&buildDirTree;
+    } else {
+	die "$gd: no directory given\n";
+    }
+} else {
+    &gotoDirectory;
+}
+exit 1;
+.TH GDPROG 1
+.SH NAME
+gdprog \- helper program for gd alias
+.SH SYNOPSIS
+.ll +8
+.B gdprog
+.RB [ " \-ib "
+]
+.RB [ " \-\-install\-bash "
+]
+.RB [ " \-it "
+]
+.RB [ " \-\-install\-tcsh "
+]
+.ll -8
+.SH DESCRIPTION
+.I gdprog
+is not supposed to be called directly, but rather through the
+alias or shell-function
+.I gd.
+Please read the man-page for gd(1) before reading any further.
+
+If
+.I gdprog
+is started with one of the options mentioned below (and above), it will
+output a string suitable for installing the alias in the specified
+shell. Thus, to install the alias, you may evaluate the output from
+.I gdprog
+as in
+
+    eval `gdprog \-\-install\-bash`
+
+If
+.I gdprog
+is not in a directory mentioned in your PATH-variable, you must
+enter the full path to the program.
+
+If the first argument to
+.I gdprog
+is "gd", it assumes it is called from the alias, and behaves as
+another program (See gd(1) for details). Thus, if you want to install
+the alias manually, you should pass "gd" followed by any parameters
+given to the alias.
+
+After successfully locating a directory,
+.I gdprog
+outputs the full directory name, and exits with success. In that case
+the alias should store the output in a shell-variable, and pass it to
+.IR cd .
+
+All messages are written to stderr, so they will be visible even
+if stdout is redirected. If
+.I gdprog
+returns with failure, a suitable error-message is displayed, so the
+alias should do nothing.
+.SH OPTIONS
+.TP
+.B \-ib, \-\-install\-bash
+Output a string that will install a bash-function for
+.IR gd .
+.TP
+.B \-it, \-\-install\-tcsh
+Print a command suitable for installing the
+.IR gd -
+alias in tcsh.
+.PP
+Please let me know of installation strings for other shells...
+.SH SEE ALSO
+gd(1)
+.SH AUTHOR
+This perl-program was written from scratch in 1994 by Sverre H. Huseby,
+Norway (sverrehu@ifi.uio.no)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.