dirabbrev - dynamic abbreviations for directories (paths)
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
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.
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.
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.
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.
Carsten Dominik <dominik@science.uva.nl>
This program is free software. See the source file for the full copyright notice.
The abbreviation list is stored in the file ~/.dirabbrev.
csh(1), tcsh(1), sh(1), bash(1), ksh(1)
The idea for this command is due to Sacha Hony who also implemented it as a set of shell scripts.