Giter VIP home page Giter VIP logo

dirabbrev's Introduction

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 v 'da -l'
alias r 'da -r'

da -s name [directory]     # Store abbrev for directory
s name [directory]         # Same as previous line, uses "S"
v                          # List (view) 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 alias and an environment variable 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 switch from the definition. If you don't want to define aliases for the abbreviations, leave out the -a switch 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. NAME is always converted to lower case. When DIRECTORY is omitted, the current working directory is used. When name is also omitted, list abbreviations for the current directory.

-l

List the available abbreviations, sorted alphabetically.

-L

Same as -l, but sorted by directory path.

-h [directory]

List all abbreviations pointing to DIRECTORY. When DIRECTORY is omitted, the current working directory is used.

-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.

-S shell

Select the syntax appropriate for SHELL. Supported shells are bash, sh, zsh, ksh, csh, and tcsh. Normally dirabbrev can figure out the correct shell syntax by itself, so this option is only a fallback for strange or buggy setups where this might not work.

-v

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

-q

Quiet. Write no messages at all.

The options -s, -l, -h, -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

v
> 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

No known bugs.

AUTHOR

Carsten Dominik <[email protected]>

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.

dirabbrev's People

Contributors

cdominik avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.