cdlist - Directory Management Package for Korn Shell
[Syntax] [Description] [Download and Installation] [Detailed Function Descriptions] [Environment Variables]
[Examples] [Files] [Platforms Supported] [Author, Copyright & Disclaimer]
Cdlist exposes the following functions to a sourcing ksh instance:
- cd <directory>
- cdi number
- cli number
- saveloadfile <file>
- overloadfile <file>
Cdlist is a directory management package contained in the file cdlist.ksh which must be sourced to be useful:$ . cdlist.ksh $It’s usually a good idea to put the source command as the last command in your $ENV file (a file sourced by a login ksh instance if the instance proves to be an interactive shell). Doing so will export necessary variables and functions for use and (in the case of the functions) aliasing, confined only to interactive shells.
Cdlist provides several features not found in other directory history management packages.
- Each directory visited is exported to an environment variable
- Directory names may contain spaces, even on Unix
- The directory list may be saved in a file on command
- A directory list is loaded from a file when cdlist is initialized;
- The directory list may be reset to known values on command
- The umask may be set to different values for paths not containing the username
- Individual directory entries may be cleared at will
- Portable to any version of ksh that supports array variables
The latest version of cdlist can be downloaded from www.pauahtun.org/pub/cdlist.zip; the zip file includes this documentation.
To install, simply unzip cdlist.zip anywhere you want, and then copy cdlist.ksh in a convenient place, such as your home directory, or some special subdirectory of ~. In your $ENV file, add this line at or near the end:. cdlist.kshIf you are running on a Windows95/98/NT machine, you should probably change the above to:export NULLDEV=c:/dev/null # Or whereever you happen to have a /dev/null. ... export <any other variables you choose to modify> export <see the Environment Variables section> . cdlist.kshIf you have directories that you wish to be included in the directory list whenever an interactive ksh session is started, place the directory names in a file named .preloaddirs in your home directory. Edit the file, and place all the directories on a single line, separating individual names with the | character. For example, the line:d:/Users/Ivanlan|d:/Users/Ivanlan/KshStuff|e:/|e:/DB|e:/Maya|e:/inetpub/wwwroot|k:/Program Filesis in my .preloaddirs file on one of my Windows NT machines.
cdSyntax: cd or cd <directory>
An alias for an internal function, which performs an unaliased cd; searches the exported array variable $_ll for a match for the new current directory. If no directory is specified, ~ becomes the current directory. The current directory before the cd becomes $_oi, used in the bk function. If a match is found for the new current directory, nothing else is done; otherwise, the new current directory is stored in the array variable $_ll. All directories in the $_ll list are made available in the environment under names following the pattern $dn, where n is the index of the directory in the array variable $_ll. The umask is set appropriately.
cdiSyntax: cdi index
Searches for index (a number greater than or equal to 0) in the current directory list. If found, cds to that directory and performs all other cd functions too. My preferred alias for this function is “@”, so that, for example, “@ 0” sets the current working directory of my shell to my home directory (0 is, by default, the index of $HOME).
cliSyntax: cli index
Clears the directory at index and resets the $_ll array variable to eliminate index discontinuities.
Performs a cdi to the next numerically greater index in the directory list; on overflow, reverts to index 0.
Performs a cdi to the next numerically lesser index in the directory list; if the index would become < 0, changes to the highest index in the directory list.
Changes to the last visited directory in the list, effectively swapping the values of $_i and $_oi.
saveloadfileSyntax: saveloadfile <file>
Writes the entire directory list array to file, or to ~/.preloaddirs if no file is specified. This is never performed automatically, so that the contents of ~/.preloaddirs may be preserved across sessions.
overloadfileSyntax: overloadfile <file>
Reads file, or ~/.preloaddirs if file is not specified, converting the contents to an array variable. The syntax of the file is extremely simple; it’s just a single line containing directory names separated by ‘|’ characters.
Displays the entire directory list, one line per entry. Directory entries are numbered, starting with 0, representing the index of that directory in the $_ll array. The current directory is marked with the $blank$arrow combination (). The last visited directory is marked with the $foobar character (, or ). If the current and last directories are the same, this is marked with the $foobar$arrow () combination.
$NULLDEVIf this variable is set, its value is used instead of /dev/null.
$OSIf this variable is set to a value containing the string “Windows”, then the internal variable _igncase is set, and directory list matches and searches are case-insensitive. On Windows95/98, you may need to set and export this variable in your .profile yourself, due to Microsoft inconsistencies.
$insideumaskThe umask for directories that have your username somewhere in the path; if not set in the environment, the default value is 22.
$outsideumaskThe umask for directories that do not have your username somewhere in the path; if not set in the environment, the default value is 2.
$arrowCurrent directory indicator; should be the visual equivalent of three characters long. If not set in the environment, a default value is supplied:
$foobarLast directory visited indicator; should be the visual equivalent of one character long. If not set in the environment, a default value is supplied: , or
$blankFiller character; should be the visual equivalent of one character long. If not set in the environment, a default value is supplied:
$_llThe array variable containing the entire list of visited directories; it’s exported, but shells receiving the export cannot read the values contained within. Controlled entirely by cdlist.
$_iThe index of the current directory in $_ll; can be used as a read-only variable, as in $PS1, but otherwise controlled entirely by cdlist.
$_oiThe index of the last visited directory in $_ll. Controlled entirely by cdlist, although it can also be used as a read-only variable.
cdl in a ksh Window
Directory Environment Variables $d0-$d5
cdi (aliased to “@”) in a ksh Window
Using the Directory Environment Variables
Any platform that supports Ksh with array variables. The package was developed under U/WIN, which is an implementation of Ksh93 by David Korn (available at www.research.att.com). It was then transplanted, without change, to the UnixWare® implementation of Ksh88 and to the MKS version of ksh (available at www.mks.com). The only changes required were those specific to Windows.
cdlist also works well with pdksh, available at several locations on the internet.
Cdlist program and documentation copyright © 1998 by Ivan Van Laningham
Home page: http://www.pauahtun.org
Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee or royalty is hereby granted, provided that the above copyright notice appear in all copies and that both the copyright notice and this permission notice appear in supporting documentation or portions thereof, including modifications, that you make.
THE AUTHOR IVAN VAN LANINGHAM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE!
Main web site: http://www.pauahtun.org