NAME

dirabbrev - dynamic abbreviations for directories (paths)


SYNOPSIS

 alias da 'eval `dirabbrev -e -a \!*`'; da -d
 alias S 'da -s'
 alias G 'da -g'
 alias L 'da -l'
 alias R 'da -r'
 da -s name [directory]     # Store abbrev for directory
 S name [directory]         # Same as previous line, uses "S"
 L                          # List abbrevs
 G name                     # cd (go) to dir
 name                       # Same as previous line, using dynamic alias
 R name [name...]           # Remove a directory abbrev
 ls $name/*.eps             # Use environment variables


DESCRIPTION

dirabbrev is a dynamic way to define and use abbreviations for long directory paths. The user assigns a simple name to a directory. dirabbrev then automatically defines an aliases and an environment variables corresponding to this name. These can be used to quickly change to the abbreviated directory, and to use the abbreviations in any file specification in the shell. Abbreviations are stored in a file and reinstalled in every new shell.

dirabbrev needs to be called through an alias or shell function. For the (t)csh, the required alias is:

   # define da and immediately call it to initialize the environment.
   alias da 'eval `dirabbrev -e -a\!*`'
   da -d

For sh/bash/ksh, you have to use a function:

   # define da and immediately call it to initialize the environment.
   function da () { eval `dirabbrev -e -a \$*`; }
   da -d

If you don't want to define environment variables for the abbreviations, leave out the -e from the definition. If you don't want to define aliases for the abbreviations, leave out the -a from the definition.

With this definition you can call da with different options, like da -s name etc. For convenience, it is recommended to define additional aliases for ``da -s'', ``da -g'' etc, see above under SYNOPSIS.


OPTIONS

-s name [directory]
Store NAME as an abbreviation for DIRECTORY. When DIRECTORY is omitted, the current working directory is used. NAME is always converted to lower case.

-l
List the available abbreviations, sorted alphabetically.

-L
Same as -l, but sorted by directory path.

-g name
Use cd to change to the directory associated with the abbreviation NAME. Name may also be a unique abbreviation of an abbreviation.

-r [name ...]
Remove the abbreviation NAME from the list. NAME may contain an exact name or a wildcard expression matching names. If NAME is omitted, remove all abbreviations pointing to the current directory.

-R [name ...]
Run a loop over all abbreviations and ask if any should be removed. If arguments are given, only try abbreviations matching any of the given wildcard patterns. When prompted, you can reply [y]es, [n]o, [a]ll, or [q]uit.

-d
Define environment variables and/or aliases for all directory abbreviations. Must be combined with -e and/or -a switches.

-u
Undefine environment variables and aliases for all directory abbreviations. Must be combined with -e and/or -a switches.

-e
Automatically track all abbreviations with corresponding environment variables. This means, when a new abbreviation is defined/deleted with -s/-r, the corresponding environment variable will automatically be defined/removed.

-a
Automatically track all abbreviations with corresponding alias definitions. This means, when a new abbreviation is defined/deleted with -s/-r, the corresponding alias will automatically be defined/removed.

-v
Verbose. Write additional messages about what is happening to STDERR.

-q
Quiet. Write no messages at all.

The options -s, -l, -g, -r are mutually exclusive. The options -d and -u are mutually exclusive as well, but (for example) -sdev is allowed.


EXAMPLES

The examples below assume that the aliases ``S'', ``L'', ``G'', and ``R'' have been defined as shown above under SYNOPSIS (recommended). If not, just replace these letters with ``da -s'' etc.

Go to a directory and store ``paper'' as an abbreviation for it

    cd /home/dominik/tex/science/paper_vega_stars/version2
    S paper

Go to another directory and store ``poster'' as an abbreviation for it

    cd ~/posters/workshop_copenhagen
    S poster

List the available abbreviations

    L
    > paper  /home/dominik/tex/science/paper_vega_stars/version2
    > poster /home/dominik/posters/workshop_copenhagen

Go back to the first directory. dirabbrev supports three different ways to do this:

    G paper                          # works always
    cd $paper                        # with environment variable tracking
    paper                            # with alias tracking

List the .eps files in the poster directory.

    ls $poster/*eps

Copy a file to the poster directory

    cp figure2.eps $poster/

Remove all abbreviations starting with ``p''. Note that wildcard characters have to be quoted to protect them from the shell.

    R p\*

If a directory path contains space characters, environment variables must be enclosed in double quotes for correct interpretation in the shell. For example, if /path/to my/poster is abbreviated as poster, you need to type commands like this:

    cd "$poster"
    cp "$poster"/*eps .

Aliases defined by dirabbrev as well as da -g work correctly also with such file names.


BUGS

In order to work correctly, dirabbrev must know under what shell it is running. Currently, it obtains this information from the environment variable SHELL, which contains the login shell of the user. This causes problems if a user with a login shell (for example tcsh) uses temporarily a different shell (for example bash). If anyone knows a simple way how to determine the current shell in perl, let me know.


AUTHOR

Carsten Dominik <dominik@science.uva.nl>

This program is free software. See the source file for the full copyright notice.


FILES

The abbreviation list is stored in the file ~/.dirabbrev.


SEE ALSO

csh(1), tcsh(1), sh(1), bash(1), ksh(1)


ACKNOWLEDGMENTS

The idea for this command is due to Sacha Hony who also implemented it as a set of shell scripts.