Written by Phil Braham. Realtime Software Pty Ltd.
Released under GNU license. Free to use. Please pass any modifications
or comments to the author Phil Braham:
realtime@mpx.com.au
===============================================================================
cdll is a replacement for cd and incorperates similar functionality to the bash
pushd and popd commands but is independant of them.
This version of cdll has been tested on Linux using Bash. It will work on most
Linux versions but will probably not work on other shells without modification.
Introduction
============
cdll allows easy moving about between directories. When changing to a new direcory
the current one is automatically put onto a stack. By default 50 entries are kept but
this is configurable. Special directories can be kept for easy access - by default up to
10 but this is configurable. The most recent stack entries and the special entries can
be easily viewed.
The directory stack and special entries can be saved to, and loaded from, a file. This
allows them to be set up on login, saved before logging out or changed when moving project
to project.
In addition, cdll provides a flexible command prompt facility that allows, for example, a
directory name in colour that is truncated from the left if it gets too long.
Setting up cdll
===============
Copy cdll to either your local home directory or a central directory such as /usr/bin
(this will require root access).
Copy the file cdfile to your home directory. It will require read and write access. This a
default file that contains a directory stack and special entries.
To replace the cd command you must add commands to your login script. The login script
is one or more of:
/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
~/.bashrc
/etc/bash.bashrc.local
To setup your login, ~/.bashrc is recommended, for global (and root) setup add the commands
to /etc/bash.bashrc.local
To set up on login, add the command:
.
/cdll
For example if cdll is in your local home directory:
. ~/cdll
If in /usr/bin then:
. /usr/bin/cdll
If you want to use this instead of the buitin cd command then add:
alias cd='cd_new'
We would also recommend the following commands:
alias @='cd_new @'
cd -U
cd -D
If you want to use cdll's prompt facilty then add the following:
CDL_PROMPTLEN=nn
Where nn is a number described below. Initially 99 would be suitable number.
Thus the script looks something like this:
########################################
# CD Setup
########################################
CDL_PROMPTLEN=21 # Allow a prompt length of up to 21 characters
. /usr/bin/cdll # Initialise cdll
alias cd='cd_new' # Replace the built in cd command
alias @='cd_new @' # Allow @ at the prompt to display history
cd -U # Upload directories
cd -D # Set default action to non-posix
########################################
The full meaning of these commnds will become clear later.
There are a couple of cavaets. If another program changes the directory without
calling cdll then the directory won't be put on the stack and also if the prompt
facility is used then this will not be updated. Two programs that can do this are
pushd and popd. To update the prompt and stack simply enter:
$ cd .
To display the current stack staus simply enter:
$ @
Note that if the previous entry on the stack is the current directory then the stack
is not updated.
Usage
=====
cd [dir] [0-9] [@[s|h] [-g []] [-d] [-D] [-r] [dir|0-9] [-R] [|0-9]
[-s] [-S] [-u] [-U] [-f] [-F] [-h] [-H] [-v]
Go to directory
0-n Goto previous directory (0 is previous, 1 is last but 1 etc)
n is up to max history (default is 50)
@ List history and special entries
@h List history entries
@s List special entries
-g [] Go to literal name (bypass special names)
This is to allow access to dirs called '0','1','-h' etc
-d Change default action - verbose. (See note)
-D Change default action - silent. (See note)
-s Go to the special entry *
-S Go to the special entry and replace it with the current dir*
-r [] Go to directory and then put it on special entry *
-R [] Go to directory and put current dir on special entry *
-a Alternative suggested directory. See note below.
-f [] File entries to .
-u [] Update entries from .
If no filename supplied then default file (/home/pbraham/cdfile) is used
-F and -U are silent versions
-v Print version number
-h Help
-H Detailed help
- - sign on its own as the first param means do not put the current directory on
the stack
*The special entries (0 - 9) are held until log off, replaced by another entry
or updated with the -u command
Alternative suggested directories:
If a directory is not found then CD will suggest any possibilities. These are
directories starting with the same letters and if any are found they are listed
prefixed with -a where is a number. It's possible to go to the directory
by entering cd -a on the command line.
The directory for -r or -R may be a number. For example:
$ cd -r3 4 Go to history entry 4 and put it on special entry 3
$ cd -R3 4 Put current dir on the special entry 3 and go to history entry 4
$ cd -s3 Go to special entry 3
Note that commands R,r,S,s and a may be used without a number and refer to 0:
$ cd -s Go to special entry 0
$ cd -S Go to special entry 0 and make special entry 0 current dir
$ cd -r 1 Go to history entry 1 and put it on special entry 0
$ cd -r Go to history entry 0 and put it on special entry 0
$ cd -a Go to the first suggested directory
A dash (-) as the first parameter means that the current directory is not put on stack:
$ cd - ../testDir Go to testDir
$ cd - -s4 Go to special entry 4
$ cd - Go to most recent stack entry
In each case the current directory is not put on the stack
Non-default mode is now set - entering cd with no parameters is the same as entering cd 0
Use cd -d or -D to change default cd action
The previous directories (0-50) are stored in the environment variables CD[0] - CD[50]
Similarly the special directories S0 - 9 are in the environment variable CDS[0] - CDS[9]
and may be accessed from the command line
The default pathname for the -f and -u commands is /home/pbraham/
The default filename for the -f and -u commands is cdfile
Set the following environment variables:
CDL_PROMPTLEN - Set to the length of prompt you require.
Prompt string is set to the right characters of the current directory.
If not set then prompt is left unchanged.
Note that this is the length of the directory name. If there is a node
name prefixed to the prompt then this will not be truncated.
CDL_PROMPT_PRE - Set to the string to prefix the prompt.
Default is:
non-root: Sets colour to blue.
root: Sets colour to red.
CDL_PROMPT_POST - Set to the string to suffix the prompt.
Default is:
non-root: Resets colour and displays $.
root: Resets colour and displays #.
Version: 1.3.0 Date: 16-DEC-2004